Eclipse Force.com IDE Editor Configuration Preferences

Eclipse can be setup to display code in an infinite number of ways. The following settings are how I like to configure the Eclipse Force.com IDE.

  • Spaces instead of tabs
  • Show line numbers
  • Show whitespace characters
  • Show a print margin

These settings can be changed at: Window -> Preferences -> General -> Editors -> Text Editors

Eclipse Editor Configuration

Click the “configure visibility” link next to the show white space setting to add fine tuning. I always uncheck the the trailing carriage return and line feed boxes and increase the opaqueness.

Eclipse White Space Characters

Javascript Popup Window Tips for Salesforce

Check if a Popup Blocker Prevented the Popup Window

Most browsers will block popup windows the first time a popup window tries to appear. Here is how to check if a popup window was blocked.

Modal Window

Making a popup window modal helps prevent it from being lost behind the main browser window. The following technique makes the popup window display above the window that created it. However, it doesn’t force the window to stay on top when other tabs or applications have focus.

Refresh or Change the Original Page’s Location

A popup window may be used to alter information related to what is displayed on the page that initiated the window. This may require the original page to be refreshed or redirected. Assign the URL to the window.opener.location.href property to change opener’s page.

Custom Button to Refresh the Original Page

Custom Buttons that use Javascript can do a lot. However, security in modern browsers can make it tricky to refresh or change the URL of the originating page. One way to do this is to have the originating page monitor the popup window that was created. The page can then refresh itself when the popup window no longer exists in memory.

Custom button code:

Change the Window Size

Changing the window height to adapt to content within the page can be frustrating because of variations in different browsers. Below is an example of one way to do it. I would not call it pretty, but it works well enough. First, it sets an initial size for the page. This is to specify the width, and the content will flow down the page based on the width. Second, we set the page size again because we can now tell the height based on the new width. Please comment if you’ve found a better light weight way to do this.

Javascript in the Popup Window:

Close Popup after a Successful Action

A popup window may ask for user input and automatically close when processing has completed successfully. The controller can set a Javascript Boolean variable on success, and the portion of the form that is rerendered can have a script assign a true/false value. Then a method that evaluates if the window should be closed can check the value of that variable.

References

Mozilla – Window open
Mozilla – setInterval
Bob Buzzard – VisualForce Lookup

Salesforce Describe Methods – Record Types, Fields, and Global Describe

Record Type Describe

Getting an object’s record type Id is simple with the statement below, and it avoids using a SOQL statment on the RecordType object. However, the method name is misleading because getRecordTypeInfosByName actually retrieves the record type with the Label and not the Name. Also, be careful because the name is case sensitive. A Null Pointer Exception will be thrown if the label does not match exact spelling and case, so add appropriate error handling.

Continue reading

In-line Editing Visualforce Component for Any Object

This is a Visualforce component for in-line editing of an object’s child or related records. It will work for most Salesforce standard and custom objects. Pass in parameters to change what is displayed and if the user can add, edit, or delete records.

In-line Editing Visualforce Component for any object

Required Parameters

  • aParentRecId: Parent Record Id. This is used to select the related object’s records.
  • aRelationField: Field that refers back to the parent. This field is used in the query where condition with the Parent Record Id.
  • asObjectType: Type of child Object.
  • aFieldList: List of fields to display in the pageBlockTable.

Optional Parameters

  • aAllowAdd: Ability to add new records. The Add button will display.
  • aAllowEdit: Ability to edit records. The Edit link will display.
  • aAllowDelete: Ability to delete records. The Del link will display.
  • aLabelOverrideFieldList: List of fields with overridden labels.
  • aLabelOverrideTextList: List of text that overrides the field labels.
  • aDefaultValueFieldList: List of fields used to set default values on added records.
  • aDefaultValueTextList: List of text used to set default values on added records.
  • aBlockTitle: Page block title text.

Continue reading

Visualforce Table with Alphabet Filter and Sortable Columns

This Visualforce page contains apex:pageBlockTable to demonstrate a few different concepts.

  • Sortable Columns in an apex:pageBlockTable
  • Alphabet Filter that filters on the current sorted column
  • Use of the ApexPage StandardSetController
  • Selecting an individual record in the table using a link
  • Selecting multiple records with a column of checkboxes using a Sub Class(Wrapper Class) to hold the boolean value.

Both single and multiple record selection were included for demonstration. Most actual projects would only require one type, and I thought it would be easy to cut whatever was not needed. The search for the Billing Address fields was consolidated into one field to make the interface simpler. Below is an example of what the Visualforce table looks like with the alphabet filter, sorted columns, address search, and checkbox record selection.

Sortable apex:pageBlockTable, alphabet filter, checkbox selection and link selection
Continue reading