[SalesForce] How to accept generic “SObject” in Lightning Web Component for Flows

I've got a custom built LWC to be used within a screen component in a flow.
My component basically renders a collection of SObjects in a distinct way.
It can also deal with different types of sObjects.

The only thing I cannot get working is my design time configuration file.
I want to register the property to allow the user to bind any kind of sObject collection (Account, Contact, Custom Object, etc.) to that property in the Flow Builder.

This is my configuration:

<targetConfigs>
  <targetConfig targets="lightning__FlowScreen">
    <property name="records" label="Record collection" type="@salesforce/schema/Account[]" role="inputOnly"/>
  </targetConfig>
</targetConfigs>

This works – but limits the user to provide an Account collection.

I've tried all of the following – without success:

type="@salesforce/schema/SObject[]"

Result: Invalid reference SObject of type sobjectClass in file recordPicklist.js-meta.xml

type="@salesforce/schema/Object[]"

Result: Invalid reference Object of type sobjectClass in file recordPicklist.js-meta.xml

type="Object[]"

Result: Type 'Object[]' is either not supported by 'lightning__FlowScreen' or does not exist.

Can anybody tell me how to achieve this?

Thanks!

Best Answer

Generic SObject and SObject[] are not yet supported at the interface between LWC and Flow (TLDR: You can't get there from here). We're working on it right now, though, and hope to get it into Summer '20. You can get an early taste for some of the experience by looking at how we implemented it for Apex Invocable Actions in Spring '20

We don't have any short-term plans to support Object and Object[] in Flow, but if you have a use case where you want to work with very freeform data structures, take a look at the support for Apex-Defined Types. Basically, if you design classes in Apex that match your data structure, you can then pass instances of that type across Flow, LWC, and Invocable Action boundaries. A good intro to that is here.

Related Topic