Setting flow finish behavior without a custom controller
Until now, in order to redirect the user to a record created in a flow, you needed to embed the flow in a visualforce page, and use a custom apex controller to get the record Id from the flow so you can use pass it to a pagereference method and direct the user to the record.
This meant that you could not use lightning runtime (as flows embedded on visualforce pages will only use classic runtime) and that you needed to write up a custom controller.
No longer! With winter18, you can use the lightning flow component on a visualforce page - and that component automatically has access to flow variables via the outputVariables variable/property. (i have very limited js knowledge so please share the correct terminology).
Start with the sample code on developerforce.
It has a couple of issues and will not work as written, but a fine fellow who goes by Charles T on sfse guided me to a working proof-of-concept.
The two issues w the code as wrriten are
- the statusChange function will never be called.
- the provided structure of the for…in loop will pull the keys, not the values,
the ways to address this are documented in the answer
add this property/parameter when you instantiate the flow component with lightning.createComponent :
{"onstatuschange":statusChange}
pull in the variable value using the key
for (key in outputVariables){
if outputVariables[key].name == 'vaOutput' {
// make your decisions here
}
}
and you can watch a sample here : https://video.twimg.com/tweet_video/DQIQJvjW0AAP-UI.mp4