Build a Flow Screen Component for Multiple Objects

You can build a single flow screen component that works with any sObject, instead of building one component per object. For example, you can build one data table component and reuse it in flows that operate on accounts, contacts, cases, or any other object. With Flow Builder, admins can pick the object type when they add the component to a screen.

To enable multiple objects on a component, declare a generic type in the component’s configuration file using the propertyType subtag. Properties that reference the generic type then accept the concrete object type the admin selects at flow design time.

Declare a Generic Type 

In the component’s .js-meta.xml file, add a propertyType subtag inside the targetConfig for lightning__FlowScreen. The propertyType tag declares the named type that property tags can reference.

AttributeRequiredDescription
nameYesThe identifier for the generic type. Use this name, wrapped in curly braces, as the type value of any property that should use the generic type.
extendsYesThe base type the generic type extends. Must be SObject. Generic Object is not supported.
labelNoThe label for the type in the Flow Builder Object Type field. Defaults to the name value if omitted.
descriptionNoThe description shown in the Flow Builder Object Type field for this type. Use it to help admins understand what kind of object to select.
1<!-- dataTable.js-meta.xml -->
2<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
3  <apiVersion>68.0</apiVersion>
4  <isExposed>true</isExposed>
5  <targets>
6    <target>lightning__FlowScreen</target>
7  </targets>
8  <targetConfigs>
9    <targetConfig targets="lightning__FlowScreen">
10      <propertyType
11        name="T"
12        extends="SObject"
13        label="Object"
14        description="Select the object whose records you want to display in this table."
15      />
16      <property name="records" type="{T[]}" label="Records" />
17    </targetConfig>
18  </targetConfigs>
19</LightningComponentBundle>

Reference the Generic Type in Properties 

In the same targetConfig, reference the generic type by name in curly braces as the type value of any property subtag. Use {T} for a single sObject and {T[]} for a collection.

1<!-- Single record -->
2<property name="selectedRecord" type="{T}" label="Selected Record" />
3
4<!-- Collection of records -->
5<property name="records" type="{T[]}" label="Records" />

In the component’s JavaScript file, declare matching @api properties.

1// dataTable.js
2import { LightningElement, api } from "lwc";
3
4export default class DataTable extends LightningElement {
5  @api records = [];
6}

Share a Generic Type Across Multiple Properties 

If you declare multiple properties that all use the same propertyType, the admin maps the type once and all properties share the same concrete object. For example, a component that accepts both an input record and produces an output record can use the same type for both.

1<!-- dataTable.js-meta.xml (excerpt) -->
2<propertyType
3  name="T"
4  extends="SObject"
5  label="Object"
6  description="Select the object for this component."
7/>
8<property name="inputRecord"  type="{T}" role="inputOnly"  label="Input Record" />
9<property name="outputRecord" type="{T}" role="outputOnly" label="Output Record" />

Because both properties reference the same propertyType, the admin selects the object only once. All properties that reference {T} remain in sync. This is an advantage over using Apex generic sObjects in flows, where each parameter must be mapped to a concrete object independently.

Add the Component to a Flow Screen in Flow Builder 

  1. Open your screen flow in Flow Builder.
  2. On a screen element, add the generic-type component.
  3. In the component’s property panel, locate the Object Type control. Select the sObject that this instance of the component should work with.
  4. After you select the object, the component’s properties that reference the generic type update to accept values of the selected type. Map each property to the appropriate flow variable.

Custom Property Editors for Advanced Type Mapping 

For most use cases, Flow Builder’s built-in Object Type control is sufficient. For a more customized type-mapping experience, build a custom property editor and register it using the configurationEditor attribute on the targetConfig tag. For example, you can restrict which objects the admin can select, or show additional context alongside the picker.

For a complete example, see Generic SObject Input for Screen Components.

See Also