[SalesForce] Making the FinishLocation of a Flow as the newly created Record

I am creating a new record using Screen/Create Record elements of a Flow. I am starting that Flow with a customized New button. I am now attempting to make the FinishLocation as the newly created record. Here is the VF page which I am referring to with the New button in order to kick off the Flow :

<apex:page standardcontroller="Vendor_Profile__c" Extensions="New_Vendor_With_Flow_Controller2">
<flow:interview interview="{!myFlow}" name="New_Vendor_Profile" finishlocation="{!finishlocation}"/>
</apex:page>

and the class which is the Extension is this :

public class New_Vendor_With_Flow_Controller2 {

    public New_Vendor_With_Flow_Controller2(ApexPages.StandardController controller) {

    }


public flow.interview.New_Vendor_Profile myflow {get;set;}

    public New_Vendor_With_Flow_Controller2() {
    }

    public String getendID() {

        if (myflow !=null) return myflow.VarRecordID;
        else return 'home/home.jsp';
        }

    public PageReference getFinishLocation() {
        System.debug('VarRecordID ########'+ myflow.VarRecordID); 
        PageReference endlocation = new PageReference('/' + getendID());
        return endlocation;
        }
}

I am attempting to use the VarRecordID variable which I set in the Create Record element in the Page Reference.

I don't think I need to set a FinishLocation in the VF page, do I ? If I set that it will only go to that spot at the end of the Flow. I don't think I can refer to the VarRecordID variable in the FinishLocation so I didn't set one.
Anyone have any suggestions on this ?

Best Answer

Yes, you will need to set the finishLocation in the visualforce page, you will also need a screen after the record is created, this screen causes a refresh of the visualforce page which will then give the finishLocation access to the variable.

Related Topic