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
crowcoder@gmail.comcrowcoder@gmail.com 

How to redirect to new record that a Flow just created?

I've built a Flow that creates a new record for a Custom object. I'm setting a variable to the new id in the Flow, but I think my VF page is reading its value at creation, which is null. How do I set a page reference to the new id so I can redirect to the new Dispatch__c object? 

 

Controller:

public class DispatchFlowController {
	
	public Flow.Interview.New_Dispatch_Flow theFlow {get; set;}
		
	public PageReference getNewDispatchRecord(){
		if(theFlow == null)
			return null;
		else
			return new PageReference('/' + theFlow.NewDispatchId);
	}
	
}

 VF Page:

<apex:page Controller="DispatchFlowController" >
<flow:interview name="New_Dispatch_Flow" interview="{!theFlow}" 
	finishLocation="{!NewDispatchRecord}"/>
</apex:page>

 note, if I hard-code the new PageReference to an existing id it does redirect to that object instance, but obviously I don't know what id my new object will have until the end of the Flow.

Best Answer chosen by Admin (Salesforce Developers) 
crowcoder@gmail.comcrowcoder@gmail.com

Resolved. All I needed was a finish screen in the Flow. Ending on the RecordCreate step was not working.

All Answers

crowcoder@gmail.comcrowcoder@gmail.com

Resolved. All I needed was a finish screen in the Flow. Ending on the RecordCreate step was not working.

This was selected as the best answer
Michaela ChrysostomouMichaela Chrysostomou
Can you please provide us the test class?? I  find it very useful but I have problem to write the test class. I only conclude with 14%code covarage
Harish RamachandruniHarish Ramachandruni
Hi,

Show me your code i can handle it .


Regards,
Harish.R
Kory Leavitt 5Kory Leavitt 5

Hi crowcoder@gmail.com,

I tested this for my own requirements and it worked great.  However, in my flow, and button, I assign flow variables.  How do I assign variables within the controller or VF page?  Currently I do that in the button url, but can't replicate that with a visual force page.

Thanks,
Kory

Vimarsh SaxenaVimarsh Saxena

Hi,

My VF page still doesn't redirect to the new record created by flow. Here is my VF Page and Controller:

VF Page

User-added image

 

Controller

User-added image

Can someone assist please

Thank You!