Open record from Salesforce Flow

Salesforce Lightning Web Component lightning/navigation can be used to open a record from Flow.

HTML:

<template>    
</template>

JavaScript:

import { LightningElement, api } from 'lwc';
import { NavigationMixin } from 'lightning/navigation';
import {
    FlowNavigationFinishEvent
} from 'lightning/flowSupport';

export default class OpenRecord extends NavigationMixin( LightningElement ) {

    @api RecordIdToOpen;

    connectedCallback() {

        let finishEvent = new FlowNavigationFinishEvent();
        this.dispatchEvent(
            finishEvent
        );
        this[ NavigationMixin.Navigate ] ( {
            type:'standard__recordPage',
            attributes:{                
                recordId: this.RecordIdToOpen,
                actionName: 'view'
            }

        } );

    }

}

js-meta.xml:

<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>59.0</apiVersion>
    <isExposed>true</isExposed>
    <targets>
        <target>lightning__FlowScreen</target>
    </targets>
    <targetConfigs>
        <targetConfig targets="lightning__FlowScreen">
            <property name="RecordIdToOpen" label="RecordId" type="String" />
        </targetConfig>
    </targetConfigs>
</LightningComponentBundle>

Sample Flow:

Using a Screen element in the Flow, we can configure the Lightning Web Component which will open or navigate to a record.

Leave a Reply