I am trying to create a flow which creates an account record and then navigates to the newly created record detail page

VF Code

<apex:page Controller="AccFlowController" TabStyle="Account">
<br/>
<flow:interview name="CreateAccount" interview="{!myflow}" finishlocation="{!AID}" />

Apex Class code

 public class AccFlowController{

 public Flow.Interview.Quick_Account myFlow { get; set; }

 public String getmyID() {
 if (myFlow==null) return '';
  else return myFlow.accountId;
 }

 public PageReference getOID(){
 PageReference p = new PageReference('https://dev-dev ed.my.salesforce.com/'+getmyID());
 p.setRedirect(true);
 return p;
 }

}

However, when I try to save the class it is showing

Error: Compile Error: Variable does not exist: accountId

My flow has the following variable present

enter image description here

up vote 5 down vote accepted

According to the documentation on Getting Flow Variables, you should call myFlow.getVariableValue:

String accountId = (String)myFlow.getVariableValue('accountId');
  • I tried it as well. But (String)myFlow.getVariableValue('accountId'); just fetches null even though the record is successfully created. @AdrianLarson – user55791 Dec 6 at 20:42
  • That seems like a problem with your flow, not your Apex. This answer resolves what you were doing wrong in the code you posted. – Adrian Larson Dec 6 at 20:49
  • 1
    You were right. There was an issue with my flow. All I needed was a finish screen – user55791 Dec 6 at 21:07

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.