Wizards generally consist of a user interface with step-by-step instructions. Their objective is to make the user experience foolproof. Often, there’s an alternate way to acheive a wizard’s objective, but it’s usually not a straightforward process. Creating wizard-like functionality in Salesforce can be as simple or as elaborate as you wish. You can integrate all sorts of web technologies with the Force.com platform to create your user interfaces. However, the example below illustrates a technique using only Force.com’s native Apex language. This wizard’s objective is to provide the user with a step to enter some necessary information before going forward with an action.
First we’ll need to create an Apex class. This simple class will be our object’s controller extension for a Salesforce Visualforce page (the eventual wizard.)
public class SMARTbudgetItem_Controller { // our class variable. Access modifiers in Apex default to private SMART_Budget_Item__c budgetItem; // the constructor public SMARTbudgetItem_Controller(ApexPages.StandardController stdController){ budgetItem = (SMART_Budget_Item__c)stdController.getRecord(); } // our Cancel PO method... called from the Visualforce page public String cancelPO(){ if(budgetItem.Cancellation_Reason__c == null){ // Here is where the rules are enforced. If the user doesn't enter a Reason, // a message is added to the page using the native Page object and user // is returned to the step to try again. SFDC's Page object offers various // message formatting that you can tap into via their enumerations. ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.WARNING, 'You must provide a Cancellation Reason first.'); ApexPages.addMessage(msg); return null; } else { budgetItem.Status__c = 'Cancelled'; budgetItem.Date_Cancelled__c = Date.today(); budgetItem.PO_Status__c = 'Cancelled'; // update the database update budgetItem; // add a message of success and return to the page ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.CONFIRM, 'You have cancelled this Budget Item.'); ApexPages.addMessage(msg); return null; } } // our method for the "Back to Budget Item" button // our return type is an SFDC object called PageReference // All that's needed is a new instantiation with your object's ID public PageReference backToBudget(){ PageReference returnPage = new PageReference('/' + budgetItem.id); return returnPage; } }
Next we’ll create the Visualforce page. This page must contain any fields from our object that we want visible, editable, or “rule dependent” for the wizard process.
<!-- Point the page to our Apex class -->
<apex:page standardController="SMART_Budget_Item__c"
Extensions="SMARTbudgetItem_Controller" TabStyle="SMART_Budget_Item__c" >
<!-- Make the following fields accessible for DML operations but don't display-->
<apex:outputText rendered="false">
{!SMART_Budget_Item__c.Status__c}
{!SMART_Budget_Item__c.PO_Status__c}
</apex:outputText>
<apex:sectionHeader title="{!SMART_Budget_Item__c.name}" subtitle="Cancel Budget Item"/>
<!-- Status dialogs get printed here -->
<apex:pageMessages />
<apex:form >
<apex:outputPanel id="cancelReason">
<!-- Create an input field and populate with value if available-->
<p>Cancellation reason:
<apex:inputField id="reason" value="{!SMART_Budget_Item__c.Cancellation_Reason__c}" />
</p>
</apex:outputPanel>
<!-- Create a couple buttons: one that calls the Cancel PO method
and one that calls the backToBudget method -->
<p><apex:commandbutton value="Confirm Cancellation" action="{!cancelPO}"/>
<apex:commandbutton value="Back to the Budget Item" action="{!backToBudget}"/>
</p>
</apex:form>
</apex:page>
Finally, we must create a Custom Button to access the wizard. This is basically a link it to our Visualforce page. The setup takes place online using SFDC’s Builder and is best illustrated by the following screen shot. Notice we’ve selected our Visualforce page, “SMART_Cancel_PO”, for the “Content” drop down menu.

Edit Button or Link
Remember to add the button to your object’s appropriate layout.
Well, that’s it… A simple wizard for your Saleforce application. Happy cloud computing!
Related posts:
- Creating a custom bulk edit screen Salesforce gives you some native bulk edit capabilities right out...
- Visualforce – Salesforce.com’s markup language Visualforce is SFDC’s custom mark up language and represents the...
- The User, Visualforce and Apex — about a drop down menu Let’s say you coded a custom view or report using...
- Editing Profile permissions using the online SFDC Builder Here’s some helpful usability tips for editing Profile permissions in...
- SalesForce – Flash Builder Integration Announced Adobe and SalesForce have always worked well together. They are...
Related posts brought to you by Yet Another Related Posts Plugin.













|
Posted by Tom Burre on February 9, 2009 at 11:59 pm
