0

I have a custom object that has a Master-Detail relationship to the Opportunity object. I have an embedded VF page on the Opportunity that uses Javascript to check conditions on the Opportunity, and if met, opens another custom VF page. The 2nd VF page, is simply calling a flow and setting a flow finish location to a 3rd custom VF page. All works properly, however, when the finish location to the 3rd VF page occurs, it is not pulling in the ID of the newly created custom object that occurred in the flow. Can anyone help me figure out why? 1st and 2nd VF pages and the controller for the 2nd page are below:

1st VF Page (Embedded in Opp):

<apex:page standardController="Opportunity">
    <apex:includeScript value="/soap/ajax/34.0/connection.js" />
    <script type="text/javascript">
        var SFInitial = new Object();

        SFInitial.openWizard = function(){
            if(
                "{!Opportunity.StageName}" === "{!$Label.Eng_OppStage4}" &&
                "{!Opportunity.Includes__c}" !== "Yes" &&
                {!Opportunity.Stage_To_Contract__c}
            ){
                window.open(
                    "/apex/VFFormCreate?Id={!Opportunity.Id}",
                    "_blank"
                );
            }

            return this;
        };

        SFInitial.updateOpportunity = function(){
            sforce.connection.sessionId = "{!GETSESSIONID()}";

            var oppToUpdate = new sforce.SObject("Opportunity");
            oppToUpdate.Id = "{!Opportunity.Id}";
            oppToUpdate.Stage_To_Contract__c = false;

            sforce.connection.update([oppToUpdate]);

            return this;
        };

        SFInitial.updateOpportunity().openWizard();

    </script>

</apex:page>

2nd VF Page (Calls Flow & sets Finish Location):

<apex:page standardController="Opportunity" tabStyle="Opportunity" extensions="VF_SFController" action="{!SF}">

    <flow:interview name="S_Form" interview="{!myFlow}" finishlocation="{!SFid}">
    </flow:interview>

</apex:page>

Controller for 2nd VF Page:

public class VF_SFController{

public List<S_Form__c> SF {get; set;}

    private final Opportunity opp;
    public VF_SFController(ApexPages.StandardController myController){
        SF = new List<S_Form__c>();
        opp=(Opportunity)myController.getrecord();
    }

    public S_Form__c SF2 = new S_Form__c();
        public void SF(){

            SF2.Opportunity__c = opp.Id;
            SF.add(SF2);
        }

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


public PageReference SFId {
     get {
      PageReference prRef = new PageReference('/apex/VFEdit?id=' + SFOutputId);
 prRef.setRedirect(true);
      return prRef;
      }
      set { SFid = value; }
      }

     public String SFOutputId {
     get {
     String strTemp = '';

     if(myFlow != null) {
     strTemp = string.valueOf(myFlow.getVariableValue('SFId'));
     }

     return strTemp;
     }

     set { SFOutputId = value; }
    } 
}
2
  • In your flow, have you assigned Id explicitly using Assignment element in variable ? variable should be defined as Input and Output type. Commented Nov 5, 2015 at 19:27
  • Yes I did. I ended up going a different way and got it to work. Thanks!
    – J. Neilan
    Commented Nov 5, 2015 at 21:37

1 Answer 1

0

For anyone interested, I ended up getting this to work using the addFields() method in my controller and not needing a Flow after all.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .