Lightning Aura Components – Properly Use to Instantiate a Flow in LWC

lightning-aura-componentslightning-web-componentsvisual-workflow

Recently Salesforce made embedding and launching a flow via LWC available.
I have been unsuccessful at making this work even after looking through the documentation. https://developer.salesforce.com/docs/component-library/bundle/lightning-flow/documentation

It looks like you pass the flow name as well as the input variables which in this case would be a recordId. It specifically says that it takes an array in, so I added the recordId to the array and passed it in as a parameter.

html:

<template>
    <lightning-flow if:true={inputVariables}
    flow-api-name='virtual_diagnostic_notes'
    flow-input-variables={inputVariables}
>
</lightning-flow>
    
</template>

JS:

    @api recordId;

    connectedCallback(){
        //do something
        console.log('RECORD ID FOR LWC', this.recordId);
        console.log('inputVariables', this.inputVariables);

    }  
    get inputVariables() {
        return [this.recordId];
    }

I keep getting this error:

enter image description here
Any thoughts?

Best Answer

A flow has variables that you set as available for input. Each variable has a name and a type.

When passing values for these variables you must simply pass a JavaScript array of object with properties that name the variable and provide the variable type and value.

Assuming you called your variable "recordId" in the flow and it is a string that receives an ID from your LWC, you need to do the following:

get inputVariables() {
    return [
        {
            name: 'recordId',
            type: 'String',
            value: this.recordId
        }
    ];
}
Related Topic