September 20, 2021

How to pass parameter from Flow to Lightning Web Component(LWC) in Salesforce?

Sample Code:
HTML:
<template>
    <lightning-card>
        <lightning-record-view-form object-api-name="Account" record-id={accountId}>
            <lightning-output-field field-name="Name"></lightning-output-field>
            <lightning-output-field field-name="AccountNumber"></lightning-output-field>
            <lightning-output-field field-name="Type"></lightning-output-field>
            <lightning-output-field field-name="Industry"></lightning-output-field>
            <lightning-output-field field-name="Website"></lightning-output-field>
    </lightning-record-view-form>
    </lightning-card>
</template>

JS:
import { api, LightningElement } from 'lwc';

export default class FlowComponent extends LightningElement {
    
    @api accountId;

}

meta.xml:
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>52.0</apiVersion>
    <isExposed>true</isExposed>
    <targets>
        <target>lightning__FlowScreen</target>
    </targets>
  <targetConfigs>
         <targetConfig targets="lightning__FlowScreen">
             <property name="accountId" label="Account Id" type="String" role="inputOnly"/>
         </targetConfig>
  </targetConfigs>
</LightningComponentBundle>

Sample Flow:




Output:



No comments:

Post a Comment