I have a flow in SalesForce which creates a new object record and populates its fields. I then set a variable vAddendumId
in the flow. I would like to be able to reference that Id
on the corresponding VisualForce page controller, but I'm having problems getting at it. I know how to put variables into the flow from my page via URL "get" but I can't figure out the opposite direction.
Here's the code that I have now which assigns the Opportunity Id
from oid
in the URL string:
<apex:page Controller="AddendumEntryController" TabStyle="Addendum__c">
<flow:interview name="Addendum_Entry" finishLocation="{!backToAddendum}" >
<apex:param name="vOpportunityId" value="{!opptyId}"/>
</flow:interview>
</apex:page>
public with sharing class AddendumEntryController {
public ID getoppId = System.currentPagereference().getParameters().get('oid');
public Flow.Interview.Addendum_Entry AddendumEntryFlow{get;set;}
public String getOpptyId(){ return getoppId; }
public PageReference getBackToAddendum(){
PageReference send = new PageReference('/' + getaddendumId);
send.setRedirect(true);
return send;
}
}
My endgoal is to send the user to the newly created object record when the flow is complete. Which means that I need to populate getaddendumId
with the id from the flow.
Thanks in advance for any help given!
I have tried a couple more things, one of which seems to be promising but is still throwing an error. I tried setting the variable equal to AddendumEntryFlow.vAddendumId
. This gave an error about dereferencing a null object. I believe this is because vAddendumId
is not set until later in the flow, but I can't be sure.
public Flow.Interview.Addendum_Entry AddendumEntry{get;set;}
public ID getaddendumId = AddendumEntry.vAddendumId;
After a good amount of fiddling, I've worked out a solution. I needed to set the interview
attribute on the page so that i could pull values from its contents. Then all that I needed to do was pull the value out of AddendumEntry.vAddendumId
.
<apex:page Controller="AddendumEntryController" TabStyle="Addendum__c">
<flow:interview name="Addendum_Entry" interview="{!AddendumEntry}" finishLocation="{!backToAddendum}" >
<apex:param name="vOpportunityId" value="{!opptyId}"/>
</flow:interview>
</apex:page>
public with sharing class AddendumEntryController {
public ID getoppId = System.currentPagereference().getParameters().get('oid');
public Flow.Interview.Addendum_Entry AddendumEntry{get;set;}
public String getOpptyId(){ return getoppId; }
public ID returnId = getoppId;
public PageReference getBackToAddendum(){
if(AddendumEntry != null) returnId = AddendumEntry.vAddendumId;
PageReference send = new PageReference('/' + returnId);
send.setRedirect(true);
return send;
}
}
It actually turned out to be pretty straight forward. The only reason my previous attempts had failed was because I had not set interview="{!AddendumEntry}"
on the page.