0

I have written a code which performs one particular automation. My objective is to display the output of type List string in the screen component of flow. When I try to create a new single record variable in the flow to display the output, I get this error "The number of results does not match the number of interviews that were executed in a single bulk execution request".

Please let me know how I can modify the code or any change in the flow variables needed to display the output. Note: the code is working fine as expected when I run from Anonymous window.

ps7Name is just one variable in the list which is the input I am defining in the flow and passing to the code. My output will be the MissingList and AdditionalList lists. I have added one CombinedList also if needed.

Thanks

public class Persona_Test{

@InvocableMethod(label='Get User Details' description='Testing Persona Automation')


public static List<String> getUsersDetails (List <String> ps7Name)
{
    List<User> usrList = [SELECT Id, firstname, lastname, profile.name
                          FROM User
                          WHERE  Id IN (SELECT AssigneeId 
                                        FROM PermissionSetAssignment
                                        WHERE PermissionSet.label = :ps7Name)];
    
    Map <ID, User> usrMap = new Map<ID, user> ();
    for (User usr: usrList)
    {
        usrMap.put(usr.Id, usr);
    }
    
    
    
    //system.debug(usrList);
    
    //system.debug(usrMap);
    
    List<PermissionSetAssignment> PermList =  [SELECT AssigneeId, PermissionSet.label
                                               FROM PermissionSetAssignment WHERE AssigneeId = : usrMap.keySet()];
    //system.debug(PermList);
    
    Map<Id,List<String>> mapPermList = new Map<Id,List<String>>();
    List<string> StorePermSets = new List<String>();
    for(PermissionSetAssignment perm : PermList){
        if(mapPermList.containsKey(perm.AssigneeId)){
            List<String> temp =  mapPermList.get(perm.AssigneeId);
            temp.add(perm.PermissionSet.label);
            mapPermList.put(perm.AssigneeId,temp);
        }
        else{
            mapPermList.put(perm.AssigneeId,new List<String>{perm.PermissionSet.label});
        }
    }
    
    
    
    Map<ID, Integer> CountofPSMap = new Map<ID, Integer>();
    Map<ID, List<String>> MissingUser = new Map<ID, List<String>>();
    Map<ID, List<String>> AdditionalUser = new Map<ID, List<String>>();
    List<String> MissingList= new List<String>();
    List<String> AdditionalList= new List<String>();
    // to store the count of PS
    for (Id idvalue: mapPermList.keyset())
    {
        Integer count=0;
        for (String s: mapPermList.get(idvalue))
        {
            //system.debug(' Map keyset Id Value' + idValue );
            //system.debug(' list values : '+ s);
            count++;
            CountofPSMap.put(idvalue, count);
            
        }
        if (count<5)
        {
            String str = String.join( mapPermList.get(idvalue), ', ' );
            string concatenate='User ID:'+ '' + idvalue + ' '+ '' + 'PS assigned:' + str + '\n';
            //MissingUser.put(idvalue, mapPermList.get(idvalue));
            MissingList.add(concatenate);
            //system.debug('Missing PS User---->' + MissingList);
        }
        else if (count>5)
        {
            String str2 = String.join( mapPermList.get(idvalue), ', ' );
            string concatenate2='User ID:'+ '' + idvalue + ' '+ '' + 'PS assigned:' + str2 + '\n';
            //AdditionalUser.put(idvalue, mapPermList.get(idvalue));
            AdditionalList.add(concatenate2);
            //system.debug('Additional PS User---->' + AdditionalList);
        }
        
    }
    //system.debug(CountofPSMap);
    system.debug('Missing PS User---->' + '\n' + MissingList);
    system.debug('Additional PS User---->' + '\n' + AdditionalList);
    List<String> CombinedList= new List<String>();         
    CombinedList.addAll(MissingList);
    CombinedList.addAll(AdditionalList);
    return CombinedList;

}}
0

1 Answer 1

0
  1. Even though your Invocable Apex Class is accepting List
  2. But in the Flow you need to pass String value One by One

Not the answer you're looking for? Browse other questions tagged .