Ask Search:
Steve ConnellySteve Connelly 

Is there a way to have a flow automatically open the new record it just created?

Working in Lightning...

I have a flow that creates a new Opportunity. Currently the flow ends in a "Success" screen with a link to the new opportunity. the user can click the link to open the opp.

Is there a way to bypass that last step and have the new opp open upon completion?

Thanks much,
Steve
Best Answer chosen by Steve Connelly
Deepak AnandDeepak Anand
User-added image
<aura:component implements="lightning:availableForFlowScreens">
    <aura:attribute name="url" 
                    type="String" 
                    access="public"></aura:attribute>
    
    <aura:handler name="init" 
                  value="{! this }" 
                  action="{! c.navigateToURL }"></aura:handler>
</aura:component>


User-added image
({
    navigateToURL : function( component, event, helper ) {
        let url = component.get( "v.url" );
        
        if( !$A.util.isEmpty( url ) ) {
            $A.get( "e.force:navigateToURL" ).setParams(
                {
                    "url" : url
                }
            ).fire();
        }
    }
})


User-added image
<design:component>
    <design:attribute name="url"
                      label="URL"
                      description="Automatically navigate to the specified URL" />
</design:component>

Watch this video - https://screencast-o-matic.com/watch/cqQY1gtNud

All Answers

Deepak AnandDeepak Anand
How is this invoked @Steve?
Steve ConnellySteve Connelly
The flow is launched from an account record using a quick-action.
Sc
Steve ConnellySteve Connelly
It is actually a fairly involved flow with a number of decision nodes and four possible Opportunity creation outcomes. Currently I am using the work-around suggested by Narender Singh in an earlier thread of yours. I just end each path with a success screen and a link to open the new Opportunity. I was just hoping for a little wow factor of opening the new Opp directly for the user.
Sc
Deepak AnandDeepak Anand
User-added image
<aura:component implements="lightning:availableForFlowScreens">
    <aura:attribute name="url" 
                    type="String" 
                    access="public"></aura:attribute>
    
    <aura:handler name="init" 
                  value="{! this }" 
                  action="{! c.navigateToURL }"></aura:handler>
</aura:component>


User-added image
({
    navigateToURL : function( component, event, helper ) {
        let url = component.get( "v.url" );
        
        if( !$A.util.isEmpty( url ) ) {
            $A.get( "e.force:navigateToURL" ).setParams(
                {
                    "url" : url
                }
            ).fire();
        }
    }
})


User-added image
<design:component>
    <design:attribute name="url"
                      label="URL"
                      description="Automatically navigate to the specified URL" />
</design:component>

Watch this video - https://screencast-o-matic.com/watch/cqQY1gtNud
This was selected as the best answer
Steve ConnellySteve Connelly
Just to make sure I understand, this requires a Lightning Component? Would I then use the component to launch the flow instead of a Quick Action?

Steve
Deepak AnandDeepak Anand
Please watch the video. That should answer all your queries. 😊
Steve ConnellySteve Connelly
I get it now. I will build later this morning and let you know.

Do I nee dto update anything in the component or just use the pieces as-is?

Sc
Deepak AnandDeepak Anand
Nope.
  • Just create the Component in your Org.
  • Drag it on to your Screen.
  • Setup the URL and voila!
Steve ConnellySteve Connelly
So am I reading the right? it looks like the component is essentially creating the URL option for the screen element, is that correct?

Sc
Deepak AnandDeepak Anand
No, the component DOES NOT create a URL. Instead, it receives or accepts a URL and then does the Navigation.

So at the core/heart, it does the Navigation and redirection to the newly created record or whatever URL you supply t it.
User-added image
Steve ConnellySteve Connelly
Sorry for the confusion. What I meant was the component adds the custom item "NaviageToURL" to the screen component.

User-added image

That is how the flow passes the URL to the component to execute the navigation correct?
Sc
Deepak AnandDeepak Anand
Yes, supply the URL to that component in the format - 
/<VARIABLE THAT HAS THE ID>
ie., forward-slash followed by the Id of the Record (which should possibly be inside a Variable)
Steve ConnellySteve Connelly
And just like that! It works!

Thanks again for your help sir!
Steve