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
Admin User 10161Admin User 10161 

Get selected object data from List View and pass it into Flow

Hi there,
I have created a custom object called 'Aptiv Buyer'. In this custom object I have create a list button called "Convert Buyers to Leads". I have linked this button to a Visualforce page named "PassSelectedIdsToFlowVF":
<apex:page standardController="APTIVN__NBuyer__c" recordSetVar="Buy" extensions="PassSelectedIdsToFlowVFController" lightningStylesheets="true">
    
    <flow:interview name="Convert_Buyer_List">
        <!-- Buyers is flow input variable & SelectedBuyerIDs is a property in the Apex controller -->
        <apex:param name="Buyers" value="{!SelectedBuyers}" />
    </flow:interview>
    
</apex:page>
This VF page is linked to the following Apex class:
public class PassSelectedIdsToFlowVFController {
    
    public APTIVN__NBuyer__c[] SelectedBuyers{get;set;}
    
    public PassSelectedIdsToFlowVFController(ApexPages.StandardSetController listcontroller){
        SelectedBuyers = new APTIVN__NBuyer__c[]{};
        for(APTIVN__NBuyer__c buy : (APTIVN__NBuyer__c[])listcontroller.getSelected()){
            SelectedBuyers.add(buy);
        }
    }
}
I have created the flow "Convert Buyer List" in which I created a Record Collection variable "Buyers". This is the parameter from the visualforce page that I want to linked to the flow.
However, when I run the flow and try to get a field from the record via a lookup I have this error message:
The flow failed to access the value for Loop_List_Buyers.APTIVN__FirstName__c because it hasn't been set or assigned.
and when I check the content of the variable I have:
Buyers = [APTIVN__NBuyer__c (a0Z2g000000RCHpEAO),APTIVN__NBuyer__c (a0Z2g000000RCNgEAO),APTIVN__NBuyer__c (a0Z2g000000RCDiEAO),APTIVN__NBuyer__c (a0Z2g000000RCKjEAO),APTIVN__NBuyer__c (a0Z2g000000RCA6EAO),APTIVN__NBuyer__c (a0Z2g000000RCHHEA4),APTIVN__NBuyer__c (a0Z2g000000RCTJEA4),APTIVN__NBuyer__c (a0Z2g000000RCEWEA4),APTIVN__NBuyer__c (a0Z2g000000RCVtEAO),APTIVN__NBuyer__c (a0Z2g000000RBkwEAG),APTIVN__NBuyer__c (a0Z2g000000RBnzEAG),APTIVN__NBuyer__c (a0Z2g000000RBf4EAG)]
Do you know how to fix the issue?
Regards,
Best Answer chosen by Admin User 10161
Abhishek BansalAbhishek Bansal
Hi ,

Can you collect the ids from the listcontroller and than do a SOQL to pass all the required fields in the list. Just try with the code below:
public class PassSelectedIdsToFlowVFController {
    
    public APTIVN__NBuyer__c[] SelectedBuyers{get;set;}
    
    public PassSelectedIdsToFlowVFController(ApexPages.StandardSetController listcontroller){
        SelectedBuyers = new APTIVN__NBuyer__c[]{};
        List<Id> buyIds = new List<Id>();
        for(APTIVN__NBuyer__c buy : (APTIVN__NBuyer__c[])listcontroller.getSelected()){
            buyIds.add(buy.Id);
        }
        for(APTIVN__NBuyer__c buy: [Select Id, APTIVN__Name from APTIVN__NBuyer__c where ID IN: buyIds]) {
            SelectedBuyers.add(buy);
        }
    }
}

Please take care of the syntax error and API names. Let me know if you need any further help on this.

Thanks,
Abhishek Bansal.

All Answers

Abhishek BansalAbhishek Bansal
Hi ,

Can you collect the ids from the listcontroller and than do a SOQL to pass all the required fields in the list. Just try with the code below:
public class PassSelectedIdsToFlowVFController {
    
    public APTIVN__NBuyer__c[] SelectedBuyers{get;set;}
    
    public PassSelectedIdsToFlowVFController(ApexPages.StandardSetController listcontroller){
        SelectedBuyers = new APTIVN__NBuyer__c[]{};
        List<Id> buyIds = new List<Id>();
        for(APTIVN__NBuyer__c buy : (APTIVN__NBuyer__c[])listcontroller.getSelected()){
            buyIds.add(buy.Id);
        }
        for(APTIVN__NBuyer__c buy: [Select Id, APTIVN__Name from APTIVN__NBuyer__c where ID IN: buyIds]) {
            SelectedBuyers.add(buy);
        }
    }
}

Please take care of the syntax error and API names. Let me know if you need any further help on this.

Thanks,
Abhishek Bansal.
This was selected as the best answer
Admin User 10161Admin User 10161
Hi Abhishek,
Thank you for your answer. Do you know if there is a way to select all the fields in SOQL query?
I would need that because in the future Leads might have additional fields and we want to update only the flow to add the additional fields.
Regards,
Abhishek BansalAbhishek Bansal
Hi,

I guess this should be a separate question. But I will tell you that there is no option to select all fields in SOQL. You can do some mappings with the help of Describe Sobject class but that will be tricky one.
If your original question is answered than please close this question by choosing a Best Answer to it. You can open a new one for the SOQL one.

Thanks,
Abhishek Bansal.