Disable Visualforce Buttons When Processing – apex:actionStatus

27 Dec

It is very handy to disable buttons after they have been pressed. This lets the user know that the button was in fact pressed, and it prevents the button’s action from being executed multiple times. The Visulforce component apex:actionStatus gives us an easy way to accomplish this. Here are some things to take note of in the example.

  • The command button must have a rerender parameter
  • Command buttons must be in an apex:outputPanel, so both buttons appear on the page when each apex:facet is active.
  • The action status will only disable one set of buttons for a apex:pageBlock at a time. If ‘both’ is specified for the button location, only the clicked set of buttons on top or bottom will be disabled while processing. I usually select only one location to prevent additional button clicks.
  • Add the immediate=”true” attribute to the Cancel. This bypasses Visualforce validation that would normally fire on the form.

active buttons
disabled buttons



Eclipse Force.com IDE – Indent and Beautify Apex Code

23 Dec

Eclipse doesn’t currently offer an option to beautify Apex code. Sorry about the trick title. However, I will describe techniques that will help you clean up your code’s indentation. Neither way is perfect, but they have helped me make my code more readable. In the meantime, vote up this idea for the enhancement.

Method 1: Developer Console

This technique uses the Developer Console to indent the source code. Then we refresh the code in Eclipse.

  • In the Developer Console
  • Open the class
  • Select all or just a section of code to indent
  • Press Shift + Tab
  • Save
  • In Eclipse
  • Right-click the class name
  • Select ‘Force.com’ -> ‘Refresh from Server’

Method 2: NotePad++ with the TextFX plugin

If you use Windows and don’t have NotePad++, download it now. It is an incredibly helpful free text utility. The plugin called TextFX has a feature to reindent code. The menu for TextFX plugin appears after it is installed. The plugin feature is intended for C++, but it also works well for APEX. I think this does a better job than the Developer Console.

  • Copy your code from Eclipse
  • Paste it into a Notepad++ window
  • Select ‘TextFX’ -> ‘TextFX Edit’ -> ‘Reindent C++ code’
  • Copy the indented code
  • Paste it back into Eclipse

The function will indent with tabs by default. It can be changed to use spaces by selecting ‘Settings’ -> ‘Preferences…’ -> ‘Tab Settings’.

Bonus: Indent Visualforce

This can be done in the Eclipse Force.com IDE. However, be careful because it will sometimes remove an end bracket when it is in a style attribute. For example: <div style=”width: {!MyWidth}”> will end up like <div style=”width: {!MyWidth”>

  • Select the section of Visualforce code that you want to indent
  • Press Ctrl + Shift + F

Eclipse editor preferences control the number of spaces that Visualforce is indented. To change the spacing, select ‘Window’ -> ‘Preferences’. Expand ‘Web’ -> ‘HTML Files’ -> ‘Editor’.

Visualforce Datepicker Manipulation and Day of Week Display

18 Dec

datepicker with past years and no date link

Hide the Datepicker Link for the Current Date

Show Years Before the Current Year in a Datepicker

Development would be a lot harder without stackexchange and stackoverflow. Thanks for this post that illustrated how to do this.

Show a Datepicker on a Text Field

Thanks to these sources for the help figuring this out.
DeveloperForce Boards

Show the Day of Week When a Date is Selected

The day of week is found by converting the input date into a datetime. Then we use the format method to give us the day of the week spelled out.

day of week spelled out

Code Examples

The examples below show how to remove the date link, show prior years in the datepicker, and add a datepicker to an field.



Multiselect Picklists for User Search and Selection using Apex and Visualforce

9 Dec

Below is a component that will allow you to search and select Users. It was created to mimic the experience of selecting multiple users in the Task creation window. However, it would be easy to change the reference from the User object to almost any other object.

An initial list of selected users can be assigned by passing an Id list in the component attribute aInitialRightList. The list referenced in the aCurrentRightList attribute will be updated anytime entries in the right multiselect picklist change. The aWidth attribute accepts px or %, and it sets the width of the entire component.

I’d like to thank those who posted sample code that helped me with the multiselect picklist component. I borrowed ideas and code from the following:
Custom Multi-Select picklist field in Visualforce
A Multiselect Picklist Visualforce Component

Multi Select Picklist Visualforce Component Example






Record ID and Data Retrieval from a VisualForce Controller Extension without a SOQL statement

26 Nov

Retrieve field data for a record using the Standard Controller object in a Controller Extension class

Salesforce Documentation:
Standard Controller Class
StandardController Instance Methods