3

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!

  • Did you take a look at this question here, I believe the same answer applies... salesforce.stackexchange.com/questions/52013/… – Jenny B Jun 25 '15 at 20:04
  • Thank you Jenny. I had looked at that question, but I get an code error when I try to use the line 'newID = myFlow.myId;' I changed it to 'newID = binderFlow.BinderId;', but I get an error that Variable does not exist: newID. I can't see where else newID is used in the other code, so I'm not sure what I'm doing wrong. – italiahall Jun 25 '15 at 20:06
  • Are you substituting with your variable names? I think the code in the answer might be missing creating the newId variable, but try creating it and assigning based on the same logic and using your variable names. – Jenny B Jun 25 '15 at 20:11
  • I've declared both variables for ID, but I something is still not quite right. I've posted my latest code above. – italiahall Jun 25 '15 at 20:39
3

There is a known issue describing that when the last screen creates the variable it is not accessible in visualforce. I'm hopeful that once this issue is resolved you will no longer require a screen to set the finish location.

There is also an idea to allow for the finish location to be specified in the flow, which would eliminate the need for this all together. The point threshold is up there so I would definitely recommend going and voting it up!

For now, it appears, the only way to get this to work is to follow David's answer and add a finish screen.

Side note: The reason I understand this to be the case, is because a screen will cause your visualforce page to rerender and since the variable is null at launch it will not be retrievable until after it is set and rerendered.

2

I believe part of your problem is that you are attempting to do this WITHOUT a Screen element. This task of passing a variable created inside your Flow is not possible without a Screen AFTER the variable is created. So, I feel that you'll be on a wild goose chase if you continue trying to do that part of it. Having a Screen saying "You have done X, press Next/Finish to go to the new record" is most likely what you'll need to do.

Now.... as for the actual code... I have implemented this code and it works perfectly: https://stackoverflow.com/questions/10032799/how-do-i-get-a-variable-back-from-a-flow

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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