function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Andee Weir 17Andee Weir 17 

Spring 19 Flow - Lightning component that outputs an array of Contacts

Very new to Flow so not sure if what I'm trying to achieve is possible or not.

In essense I want a flow to call a custom Lightning Component which returns an array of contacts which the flow should store in a variable for later processing.  I've defined the LC which at the moment just returns the last 10 created contacts (the real LC will allow user input & be more complex but I've stripped it right back for the moment) :-

Apex Controller :-
public with Sharing class TestReturnContactscontroller {
	@AuraEnabled
    public static list<Contact> getContacts() 
    {
        list<contact> contacts = [select id, name from contact order by createdDate desc limit 10];
        
        return contacts;
    }
}

 LC :-
<aura:component controller="TestReturnContactscontroller" implements="force:appHostable,force:lightningQuickAction,lightning:availableForFlowScreens" access="global">
	
    <aura:attribute name="contacts" type="contact[]" description="Array of contacts returned"/>
    
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
</aura:component>

LC Controller :-
({
	doInit : function(component, event, helper) {
		var action = component.get('c.getContacts');
                           
        // Define the callback
        action.setCallback(this, function(response) {
            var state = response.getState();
            
            if (component.isValid() && state === "SUCCESS")
            {
                // Callback succeeded
            	console.log('Successful response from doInit ---> ',response.getReturnValue());
                
                // Get the label of the object
                var result = response.getReturnValue();
                
                component.set('v.contacts', result);
                
            }
        });
        
        // Enqueue the action                  
        $A.enqueueAction(action); 
	}
})

LC Design :-
<design:component>
	<design:attribute name="contacts" label="contacts : return list" />
</design:component>
When I put this into a Flow I can see the console.log statement & an array of 10 contact ids/names.  However I cannot work out how to get these results into a flow variable.  In my flow I've created a Screen which contains my LC but the the field for 'contacts' in the Store Output Values only seems to want a variable for a single contact not one that I've defined as a collection.  Is what I am trying to do possible & if so, what am I doing wrong?

Thanks in advance for any help.
Best Answer chosen by Andee Weir 17
Andee Weir 17Andee Weir 17
I think it was due to a caching issue.  If I came right out of the flow & then went back in, the flow recognised that the output variable was a collection & allowed me to assign a collection variable to it.