You need to sign in to do that
Don't have an account?
Visual Flow Lightning Component Redirect
Good morning,
I have created a lightning component which runs a visual flow creating an Event record.
When the flow finishes I would like the page to be redirected to the created Event.
I have found a help topic with some example code but it would be great if someone could explain it ie. where would I add the created record id variable in my flow in this code so that it redirects?
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/components_using_flow_onfinish.htm
Thank you
I have created a lightning component which runs a visual flow creating an Event record.
When the flow finishes I would like the page to be redirected to the created Event.
I have found a help topic with some example code but it would be great if someone could explain it ie. where would I add the created record id variable in my flow in this code so that it redirects?
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/components_using_flow_onfinish.htm
handleStatusChange : function (component, event) { if(event.getParam("status") === "FINISHED") { var outputVariables = event.getParam("outputVariables"); var outputVar; for(var i = 0; i < outputVariables.length; i++) { outputVar = outputVariables[i]; if(outputVar.name === "redirect") { var urlEvent = $A.get("e.force:navigateToSObject"); urlEvent.setParams({ "recordId": outputVar.value, "isredirect": "true" }); urlEvent.fire(); } } } }
Thank you
All Answers
Make sure you are passing the flow output var from the flow ( in your case records Id as a first output var )
Really appreciate the two of you for providing the answers.
However, if you can please post the complete code for both the .cmp and .js file it will be really helpful.
I am using the following, which ain't redirecting
<aura:component access="global" implements="lightning:availableForFlowActions">
<aura:attribute name="CreatedOppRecord" type="String"/>
<aura:handler name="init" value="{!this}" action="{!c.init}" />
<lightning:flow aura:id="flowData" onstatuschange="{!c.handleStatusChange}" />
</aura:component>
({
init : function (component) {
// Find the component whose aura:id is "flowData"
var flow = component.find("flowData");
// In that component, start your flow. Reference the flow's API Name.
flow.startFlow("ConvertLeadContactFlow");
},
handleStatusChange : function (component, event) {
if(event.getParam("status") === "FINISHED") {
var outputVariables = event.getParam("outputVariables");
var outputVar;
for(var i = 0; i < outputVariables.length; i++) {
outputVar = outputVariables[i];
if(outputVar.name === "CreatedOppRecord") {
var urlEvent = $A.get("e.force:navigateToSObject");
urlEvent.setParams({
"recordId": outputVar.value,
"isredirect": "true"
});
urlEvent.fire();
}
}
}
}
})
Thanks in advance.
Regards,
Ani