function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Zoom_VZoom_V 

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 name="New_Vendor_Profile"/>
</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 ?
 

logontokartiklogontokartik
FinishLocation is not a parameter, it is an action that will trigger an Apex Controller method that can return a PageReference. You need to change your code to something like this..
 
<flow:interview name="New_Vendor_Profile" finishLocation="{!navigateToNewRecord}"/>
In you class you can write
public PageReference navigateToNewRecord() {
        System.debug('VarRecordID ########'+myFlow.VarRecordID); 
        PageReference endlocation = new PageReference('/' + getendID());
        return endlocation;
}

Hope this helps. Best.



 
Zoom_VZoom_V

Thank you very much for your input. I tried altering the code to what you suggested and I would get an error "Error: Unknown property 'Vendor_Profile__cStandardController.navigateToNewRecord'". As I have it now I changed the VF page line to : "<flow:interview interview="{!myflow}" name="New_Vendor_Profile" finishlocation="{!finishlocation}"/>" and am getting this error : System.NullPointerException: Attempt to de-reference a null object 
Class.New_Vendor_With_Flow_Controller2.getFinishLocation: line 20, column 1. 

I'm completely baffled on how to fix this. I appreciate any input I can get. 

Thanks again

logontokartiklogontokartik
Yeah comment the line 20. looks like myFlow is null and you are trying to access the Id from a null value. Also can you confirm if you defined the VarRecordId in your flow as Input & Output.

Thank you
Zoom_VZoom_V
Thank you - I commented out line 20, and I can confirm VarRecordId is Input & Output.
Zoom_VZoom_V
@logontokartik - it turns out that the Flow needed a final Screen with a Finish button. Apparently the Finish button gives the VF page enough time to refresh and so the variable is no longer null. 

Thank you for all of your help.
Michaela ChrysostomouMichaela Chrysostomou
Can you provide us the test class for the above example?