[SalesForce] Pass object from Flow to Lightning component

In a Flow, I can retrieve an object and several fields. Is it possible to pass the object to a Lightning component used in a screen? I've tried setting up an attribute as Map or Object, and adding the attribute to the Design, but when I attempt to save the Lightning component, I get errors like this:

Error:(1, 1)

The flexipage:availableForAllPageTypes interface doesn't support these attribute types in the design resource: map.

The forceCommunity:availableForAllPageTypes interface doesn't support these attribute types in the design resource: map.

The lightning:availableForFlowScreens interface doesn't support these attribute types in the design resource: map.

The flexipage:availableForRecordHome interface doesn't support these attribute types in the design resource: map.

Best Answer

So the answer was contained within a comment in this post: Is it possible to return a value from a Lightning Component to a flow?

In my Flow, I setup a variable called orderRecords of type record, and checked the Allow multiple values (collection) property.

Next, I added a get records element to my flow. Itt retrieves all of the order records with the matching recordId (passed into the Flow via a variable with that name). There is only one, but it is stored in orderRecords collection variable.

Then in my Lightning component, I defined an attribute to receive the collection variable:

<aura:attribute name="orderRecords" type="package__Order__c[]" />

and included the following in the design part:

<design:attribute name="orderRecords" label="Order records" description="Only the first one in the collection is used" />

And in my component's init(), I get the first record in the collection and save that in an attribute:

var orderRecords = component.get("v.orderRecords");
var orderObj = null;

if(orderRecords.length > 0) {
    orderObj = orderRecords[0];
    component.set("v.orderObj", orderObj);
}

Then, I updated my flow to pass the orderRecords variable to to the component as an attribute.

Its a bit of work to do things this way, for sure, but does do what I need. It certainly will be nice whenever SF updates Flows to be able to pass a single record to a component.

Related Topic