I'm attempting to run a flow from my first VF page. I was able to construct my code using the concepts I learned in another StackExchange post.
I can get the flow to run just fine using the VF page when I have my debug screens included, but when I switch from my Flow version to the Autolaunched Flow version (which doesn't include the debug screens), it crashes at the last step. I still need to figure out how to get the page to end within the edit page of the new record, but for now, I just need to figure out how to get the Autolaunched Flow to work properly.
Flow:
Step 1: Record Lookup: custom object Binder__c
Debug1: Binder Name and Sales team fields return values
Step 2: Record Lookup: custom object Coverage_Opportunity__c (parent of Binder__c)
Debug 2: Coverage Opportunity ID, Binder Name, and Opportunity name return values
Step 3: Record Create: new Binder page which pre-populates with fields from original Binder and Coverage Opportunity pages. In the 'Assign the record ID to a variable to reference in your flow' field, I have variable {!varNewBinderID}
Debug3: New Binder ID returns value
Apex Class:
public class RevisedBinderFlowController{
private final Binder__c binder;
//Classify class as extension
public RevisedBinderFlowController(ApexPages.StandardController stdController){}
// Instanciate the Flow for use by the Controller - linked by VF interview attribute
public Flow.Interview.Revised_Binder binderFlow {get;set;}
//Find new record id
public String getBinderID(){
if ( binderFlow==NULL) return'';
else return binderFlow.varNewBinderID;
}
// Set the page reference accessor methods
public PageReference getBinderPage() {
return new PageReference('/' + getBinderID());
}
Visualforce page:
<apex:page standardController="Binder__c" extensions="RevisedBinderFlowController">
<flow:interview name="Revised_Binder" interview="{!binderFlow}" finishLocation="{!BinderPage}">
<apex:variable var="CovOpp" value="{!Binder__c.Coverage_Opportunity__c}" />
<apex:param name="varCovOppID" value="{!Binder__c.Coverage_Opportunity__c}"/>
<apex:param name="varBinderID" value="{!Binder__c.ID}"/>
</flow:interview>
</apex:page>
So, I feed the BinderID and CoverageOpportunityID into the flow, and that works every time. The error comes when the page tries to render into the new record. Like I said, if I keep my debug steps in the code, and run through the VF page, it finishes directly into the new Binder page. When I run through with the Autolaunched version, the new page is still created, but I land on a page with this error message.
Invalid Page Redirection The page you attempted to access has been blocked due to a redirection to an outside website or an improperly coded link or button. Please contact your salesforce.com Administrator for assistance. For more information, see Insufficient Privileges Errors.
Click here to return to the previous page.
Any suggestions on how I can get the Autolaunched page to render properly, and how to also get the page to render into the edit version of the page, not just the saved page? Thanks!
UPDATE:
Looked at Jenny B's code on other example, and it looks different than the first time.
New controller extension code:
public class RevisedBinderFlowController{
private final Binder__c binder;
//Classify class as extension
public RevisedBinderFlowController(ApexPages.StandardController stdController){}
// Instanciate the Flow for use by the Controller - linked by VF interview attribute
public Flow.Interview.Revised_Binder binderFlow {get;set;}
//Find new record id
public String getBinderID(){
if (varNewBinderID==NULL) return'';
<--! Error: variable does not exist: varNewBinderID -->
else return binderFlow.varNewBinderID;
}
// Set the page reference accessor methods
public PageReference getBinderPage() {
if(binderFlow <> null){
getBinderID = binderFlow.varNewBinderID;
}
if(getBinderID <> null){
PageReference p = new PageReference('/' + getBinderID());
p.setRedirect(true);
return p;
}else{
return null;
}
}
}
NEXT UPDATE:
Followed Jenny B's advice and updated the extention code to declare variables:
public class RevisedBinderFlowController{
private final Binder__c binder;
public Id varNewBinderID;
public ID getBinderID;
//Classify class as extension
public RevisedBinderFlowController(ApexPages.StandardController stdController){}
// Instanciate the Flow for use by the Controller - linked by VF interview attribute
public Flow.Interview.Revised_Binder binderFlow {get;set;}
//Find new record id
public String getBinderID(){
if ( varNewBinderID==null) return'';
else return binderFlow.varNewBinderID;
}
// Set the page reference accessor methods
public PageReference getBinderPage() {
if(binderFlow <> null){
getBinderID = binderFlow.varNewBinderID;
}
if(getBinderID <> null){
PageReference p = new PageReference('/' + getBinderID());
p.setRedirect(true);
return p;
} else {
return null;
}
}
}
Now I've stopped getting the error message yay, but instead of landing on the new record page, I'm landing on an end flow page that simply states "YOUR FLOW FINISHED'. I must still be mis-coding something, but making progress!