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
MasahiroYMasahiroY 

InvocableMethod : List<Ids> inputs and List<Id> outputs

Hi all, I'm working on the InvocableMethod with Flow.  What it's supposed to deliver is put List<Id> in the apex action then return unique List<Id>. Here's the code.
public class lookUpAccountAnnotation {
   @InvocableMethod
    public static List<outputParam> getAccountIds(List<inputParam> param) {
        Set<Id> uniqueIds = new Set<Id>();
        uniqueIds.addall(param[0].inputIds);

        outputParam response = new outputParam();
        response.outputIds.addAll(uniqueIds);
        
        List<outputParam> outputs = new List<outputParam>();
        outputs.add(response);
        
        return outputs;
    }

    public class inputParam {
        @InvocableVariable(required=false label='AccountIDs for input')
        public List<Id> inputIds;
    }
    
    public class outputParam {
        @InvocableVariable(required=false label='AccountIDs for output')
        public List<Id> outputIds;
    }
}
With system.debug() in each variable, you can get the Ids for param and uniqueIds, but it seems it stopped by response before reaching system.debug (response)

Do you have any solution for this? It's pretty much generic wherever you can use inputting Ids and returning unique output Ids if this code works.

Thanks!

 
Best Answer chosen by MasahiroY
ShivankurShivankur (Salesforce Developers) 
Hi Masahiro,

Try to check with below type of code in your class:
List<inputParam> inparam = param.clone();
Set<Id> outputIds = (new Map<Id,inputParam>(inparam)).keySet();
Check out this thread as well for more insight:
https://salesforce.stackexchange.com/questions/8910/how-can-i-efficiently-generate-a-setid-from-a-listsobject-structure

Hope above information helps, Please mark as Best Answer so that it can help others in the future.

Thanks.
 

All Answers

ShivankurShivankur (Salesforce Developers) 
Hi Masahiro,

Try to check with below type of code in your class:
List<inputParam> inparam = param.clone();
Set<Id> outputIds = (new Map<Id,inputParam>(inparam)).keySet();
Check out this thread as well for more insight:
https://salesforce.stackexchange.com/questions/8910/how-can-i-efficiently-generate-a-setid-from-a-listsobject-structure

Hope above information helps, Please mark as Best Answer so that it can help others in the future.

Thanks.
 
This was selected as the best answer
MasahiroYMasahiroY
Hi Shivankur, thanks for your input. It's perfect!