+ Start a Discussion
Dave BerenatoDave Berenato 

Finish Location of Apex Flow to load Standard Controller Page for New Record

Hi everyone,

I have a Visualforce page that checks for an existing Lookup record. If it does not exist, it runs a Flow Interview to create one, and if it does exist, it loads a Visualforce webform I made that uses Standard Controller for that "Application__c" custom object.

My only issue is I need the <flow: interview> FinishLocation to pull a variable ID from the record created in the Visual Workflow. How can I achieve this and reference it in the Visualforce Page?
 
public class FAIRAssistanceApplication {

     public FAIRAssistanceApplication (ApexPages.StandardController controller) {
    }
    public ID getAccId = System.currentPagereference().getParameters().get('var_AccountID');
    
    
    public Flow.Interview.NewFAIRAppAuto NewAppFlow{get;set;}
    public String getAccountId(){ return getAccId; }

    public ID AppId = NewAppFlow.var_AppID;
    
    public PageReference getAppId(){
        
        if(NewAppFlow != null) AppId = NewAppFlow.var_AppID;

        PageReference send = new PageReference('/' + NewAppFlow.var_AppID);
        send.setRedirect(true);
        return send;

    }
    
}
 
<apex:page showheader="false" standardController="Application__c" extensions="FAIRAssistanceApplication">



<apex:pageblock rendered="{!IF(ISBLANK(Application__c.Property_Account__c),TRUE,FALSE)}">
    <flow:interview name="NewFAIRAppAuto" interview="{!NewAppFlow}" finishLocation="{!AppId}')}">
    </flow:interview>
</apex:pageblock>




<apex:form rendered="{!IF(NOT(ISBLANK(Application__c.Property_Account__c)),TRUE,FALSE)}">
    <p>{!Application__c.Property_Account__r.Name}</p>
    <p>{!Application__c.Name}</p>
    <p>Employer: <apex:inputField value="{!Application__c.Employer_Position_1__c}"/></p>
<apex:commandButton id="saveBtn" value="Save" action="{!save}" />


</apex:form>

</apex:page>

 
Alain CabonAlain Cabon
Hi Dave,

What doesn't work exactly? All seems correct if NewAppFlow.var_AppID is at least an output field.

There is just a typo above for finishLocation
<apex:pageblock rendered="{!IF(ISBLANK(Application__c.Property_Account__c),TRUE,FALSE)}">
    <flow:interview name="NewFAIRAppAuto" interview="{!NewAppFlow}" finishLocation="{!AppId}">
    </flow:interview>
</apex:pageblock>

https://developer.salesforce.com/forums/?id=9060G000000BcrtQAC

 
Dave BerenatoDave Berenato
Hi Alain! Been a while.

So I have this extension as above:
 
public class FAIRAssistanceApplication {

 	public FAIRAssistanceApplication (ApexPages.StandardController controller) {
    }
    public ID getAccId = System.currentPagereference().getParameters().get('var_AccountID');
    
    
    public Flow.Interview.NewFAIRAppAuto NewAppFlow{get;set;}
    public String getAccountId(){ return getAccId; }

    public ID AppId = NewAppFlow.var_AppID;
    
    public PageReference getAppId(){
        
        if(NewAppFlow != null) AppId = NewAppFlow.var_AppID;

        PageReference send = new PageReference('/' + NewAppFlow.var_AppID);
        send.setRedirect(true);
        return send;

    }
    
}

And I go to the URL:
 
https://corere--app--c.cs71.visual.force.com/apex/FAIRAssistanceApplication?var_AccountID=0014D000009x2g9
I get the below error.

User-added image
 
Dave BerenatoDave Berenato
Hi  Alain,

Error message for the above code is "Variable does not exist: AppId"

I tried declaring the variable but that did not help (see line 22):
public class FAIRAssistanceApplication {

    public Flow.Interview.NewFAIRAppAuto NewAppFlow{get;set;}

    public ID AccId {get;set;}

     public FAIRAssistanceApplication (ApexPages.StandardController controller) {
            AccId = System.currentPagereference().getParameters().get('var_AccountID');
    }
    public String getAccountId(){ return AccId; }

    public PageReference getAppId(){
        
        if(NewAppFlow != null) AppId = NewAppFlow.var_AppID;

        PageReference send = new PageReference('/' + AppId);
        send.setRedirect(true);
        return send;

    }
    
    public ID AppId {get;set;}
    
}

So when I went to:
 
https://corere--app--c.cs71.visual.force.com/apex/FAIRAssistanceApplication?var_AccountID=0014D000009x2g9

I end on:

User-added image

When I wanted it to end on:
 
https://corere--app--c.cs71.visual.force.com/apex/FAIRAssistanceApplication?ID=a184D000001h5BY

Where "a184D000001h5BY" is the var_AppId created by the flow (this worked successfully by the way, so the last piece is just the FinishLocation.

Thank you!

 
Alain CabonAlain Cabon
Hi Dave,

I don't know if your code is complete or just an excerpt.

Only complete code and complete flow can be really fixed.
Dave BerenatoDave Berenato

Hi Alain,

That's the full code:

Visualforce Page:

<apex:page showheader="false" standardController="Application__c" extensions="FAIRAssistanceApplication">




<apex:pageblock rendered="{!IF(ISBLANK(Application__c.Property_Account__c),TRUE,FALSE)}">
    <flow:interview name="NewFAIRAppAuto" interview="{!NewAppFlow}" finishLocation="{!AppId}')}">
    </flow:interview>
</apex:pageblock>




<apex:form rendered="{!IF(NOT(ISBLANK(Application__c.Property_Account__c)),TRUE,FALSE)}">
    <p>{!Application__c.Property_Account__r.Name}</p>
    <p>{!Application__c.Name}</p>
    <p>Employer: <apex:inputField value="{!Application__c.Employer_Position_1__c}"/></p>
<apex:commandButton id="saveBtn" value="Save" action="{!save}" />


</apex:form>

</apex:page>

Which if the URL has an Account with no Application will run the below flow:

(var_AccountID in, var_AppID out)
 
https://corere--app--c.cs71.visual.force.com/apex/FAIRAssistanceApplication?var_AccountID=0014D000009x2g9

User-added image

User-added image

And then using the below class will redirect back to the Visualforce Page with the Standard Controller pulling the new AppId:
 
https://corere--app--c.cs71.visual.force.com/apex/FAIRAssistanceApplication?ID=a184D000001h5BY
 
public class FAIRAssistanceApplication {

    public Flow.Interview.NewFAIRAppAuto NewAppFlow{get;set;}

    public ID AccId {get;set;}

     public FAIRAssistanceApplication (ApexPages.StandardController controller) {
            AccId = System.currentPagereference().getParameters().get('var_AccountID');
    }
    public String getAccountId(){ return AccId; }

    public PageReference getAppId(){
        
        if(NewAppFlow != null) AppId = NewAppFlow.var_AppID;

        PageReference send = new PageReference('/' + AppId);
        send.setRedirect(true);
        return send;

    }
    
    public ID AppId {get;set;}
    
}

So the only piece I'm missing is to have the FinishLocation equal the var_AppID created in the flow.