3

I am trying to redirect the user in a flow. It works as the following:

Click on URL button -> Redirected to flow -> User fills out LWC embedded in flow -> flow creates record -> Screen flow passes newly created Id back to LWC -> Use NavigationMixin to redirect user

However the user is never redirected. They remain on the 2nd screen. As I understand it you cannot use flow variables in a URL button which is why I am trying to use NavigationMixin.

JS:

    navigateToNewOpportunity() {
        console.log('newOppId: ', this.newOppId); //passed from Flow (it is populated)
        this[NavigationMixin.Navigate]({
            type: 'standard__recordPage',
            attributes: {
                recordId: this.newOppId,
                objectApiName: 'Opportunity',
                actionName: 'view'
            }
        });
    }

XML:

<?xml version="1.0" encoding="UTF-8"?>
    <LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
        <apiVersion>54.0</apiVersion>
        <isExposed>true</isExposed>
        <targets>
            <target>lightning__FlowScreen</target>
            <target>lightning__AppPage</target>
            <target>lightning__RecordPage</target>
        </targets>
        <targetConfigs>
            <targetConfig targets="lightning__FlowScreen">
                <property name="newOppId" label="New Opportunity Id" type="String" />
            </targetConfig>
        </targetConfigs>
    </LightningComponentBundle>

2 Answers 2

2

In your JS: Does your class header look like the one in the following example?

// ... NavigationMixin import ...

// Notice the NavigationMixin(LightningElement)
export default class ExampleLWC extends NavigationMixin(LightningElement){
    //... some code ...
    navigateToNewOpportunity() {
        // your NavigationMixin code here ...
    }
}

If the class does not extend NavigationMixin, nothing happens when the script runs. The code will deploy without errors but it wont work.

Edit: Also, the component may not work when used from the Flow Debug but may work from wherever the flow is active (App page, Record Page, etc.).

1

It should work, in dreamhouse we have a flow that does exactly that, please take a look:

2
  • Could it be something with my XML. I have updated the description
    – some guy
    May 31, 2022 at 14:47
  • Can you copy the full code of your js file?
    – Alba Rivas
    Jun 1, 2022 at 8:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .