Showing posts with label ID. Show all posts
Showing posts with label ID. Show all posts

Friday, April 18, 2014

Salesforce Flow Using Record IDs at the Start or at the Finish

Salesforce Flow can be combined with Visualforce pages to provide greater flexibility and automation to the user interface so that Salesforce users have fewer opportunities for mistakes. 
Racer X doesn't always like to start with the group.

 

Start

By invoking a Flow through a Visualforce page, you have the option to create a button on the particular object you intend to manipulate.  In this example, a button on the Lead object is configured to access a Visualforce page that invokes a Flow to convert the Lead.

Because the button exists on a specific record detail page, the standard controller makes the record ID accessible for the specific data being displayed when the button is clicked.  This means that the record can be converted without additional Apex code.  The Visualforce page would look something like this:

<apex:page standardcontroller="Lead" >

    <flow:interview name="LeadConversion">
            <apex:param name="thisLeadID" value="{!Lead.Id}"/>
    </flow:interview>

</apex:page>

 Finish

Finishing the Flow by bringing the user to a specific record detail page is more difficult. The easiest solution by far is to provide the information and actions the user needs as part of the Flow rather than as something they see after the Flow is finished. 

But even the complicated solution, adding Apex code to a custom Apex controller or extension to specify a finishlocation, is not too difficult.  Simple code enables Salesforce Flow to finish on record detail page. Even so, there are some considerations for defining a finishlocation:
  • Visualforce is required to specify a finishlocation and only URLs in your Salesforce instance can be specified within the finishlocation attribute on the Flow according to documentation
  • For variable finishlocations, an Apex controller is also required
  • Rather than referencing variables as part of the finishlocation, use a variable in place of a finshlocation on the Visualforce page
Here is a simple method to add to your Apex controller code to use a specific record ID in the finish location:

        public PageReference getpRefFinishLocation() {      

            String temp = 'home/home.jsp';
            if(myflow!=null) temp = string.valueOf(myflow.RecID);
            PageReference pRef = new PageReference('/' + temp);
            return pRef;

        }

Use code like the example above to access a variable, RecID in this case, from your flow and incorporate that into the URL for the page users see when they finish executing the Flow.