• SOURAV GUHA 9
  • NEWBIE
  • 15 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 9
    Replies
Hello,
I have a code which performs one particular automation. My objeective 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 needed to display the output. Note: the code is working fine as expected when I run from Anonymous window.

ps7Name is the input which 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;

    }}



 
Hello, my use case consists of the following steps:
  1. Get the users who have 'PS_Unique' PS assigned
  2. Retrieve the permission sets assigned to every user from step 1
  3. Check the count of PS for every user
  4. Decison on count
    1. if Count>5, add this user to a List 'Additional'
    2. if Count<5, add this user to a List 'Mising'
  5. Output 'Missing' and 'Additional' Lists with details of the user along with the permission sets assigned to each of them.
I am a beginner in apex coding and am writing a code, but unfortunately, only got to the first step.
private static String ps_UniqueName = 'Order Management Agent';

//gettin users who have ps_Unique PS assigned

List<User> lstUser = [SELECT Id
                              	FROM User
                              	WHERE Id IN (SELECT AssigneeId 
                                               	FROM PermissionSetAssignment
                                               	WHERE PermissionSet.Label = :ps_UniqueName)];
                                             

//storing the list of users

List<Id> UserIds = new List<id>();

For(User usr:lstUser)
{
UserIds.add(usr.id);
}
system.debug(UserIds);

 
I have a list of permission sets (PS1-10) and one profile. Below are the steps which I need to execute:
  • First I need to find the users who have this particular profile and PS7
  • Then I need to check if the users having PS7 and this profile have all the permission sets (PS1-10) assigned to them. 
  • If there are less permission sets assigned, then return Missing, if there are more permission sets assigned, return Additional, else return No Change. I need to implement this using either Flow or Apex. 
  • The final output should give me the userID, the permission sets assigned to them and Missing/Additional/No change
Till now I have been doing this manually by querying the PermissionSetAssignment object, then retrieving the Assignee details and the permission sets assigned to the assignee, then manually checking.
 
Thank you
Scenario:- Create a Map with cityName as key,and its corresponing
======    places as values

Public class Map_Practice{
public static void mapPrac(){
    //*Create a Map with cityName as key,and its corresponing places as values
    Map<string,list<string>> myMap = new Map<string,list<string>>();
        list<string> Hplaces = new list<string>{'SRnagar','LBnagar','KBHP'};
        list<string> Bplaces = new list<string>{'Marthali','Ecity','Whitefield'};
        list<string> Cplaces = new list<string>{'Thambaram','ChromePet','TNnagar'};
            myMap.put('HYD',Hplaces);
               myMap.put('BAN',Bplaces);
            myMap.put('CHE',Cplaces);
        system.debug('City and Its Places'+myMap);
        //Get all the city names
        set<string> keys =myMap.keySet();
         system.debug('Cityes==>'+keys);
        //get all the places
        /* *if my map of values is list<string> then we can get all the values list<list<string>>*/
        list<list<string>> values = myMap.values();
           system.debug('Places==>'+values);  
        } 

}

Please Help Me i am new to salesforce
HandlerClass:-
==========
public class PreventConDuplicatePhoneByAccount {
    public static void fetchDupCon(list<contact> conList){
        for(contact c:conList){
            integer count=[select count() From Account WHERE id=:c.accountId and Phone=:c.Phone];
            if(count!=1){
                c.Phone.addError('Phone No Should Be Same As Linked Account');
            }
        }
    }
}

Trigger  Code:-
==========
trigger PreventConDuplicatePhoneByAccountTrigger on Contact (before insert,before update) {
PreventConDuplicatePhoneByAccount.fetchDupCon(Trigger.new);
}
 
on Lead creation and updation if lead status is qualified or unqualified want current date . i have written below trigger but its not working

trigger LeadTrigger on Lead (before insert,Before update) {
   if(trigger.isBefore && trigger.isUpdate){
LeadTriggerHandler.befUpdt(trigger.new , trigger.oldMap);
   }

}
------------------------------------------------------------------------------------
public class LeadTriggerHandler {
    
    public static void befUpdt(List<Lead> newLd, map<Id,Lead> oldMapLd){
        
        for(Lead ld : newLd){
           if (oldMapLd != Null && ld.status != oldMapLd.get(ld.Id).status ){
                if(ld.status == 'qualified' && ld.status ==' unqualified'){
                    ld.CreatedDate = system.now() ;
                }
            }
        }
        
    }

}

thank you,
snehal
1.Contact has Picklist values of
>>Status = Draft ,Open,Closed 
2.Account has three fields 
>>No.of .Open Contacts
>>No.of.Closed Contacts
>>No .of .Draft contacts 
write a Apex trigger to update the number of draft ,open,closed contacts on Account field  ,based on contact status .
 
I have a list of permission sets (PS1-10) and one profile. Below are the steps which I need to execute:
  • First I need to find the users who have this particular profile and PS7
  • Then I need to check if the users having PS7 and this profile have all the permission sets (PS1-10) assigned to them. 
  • If there are less permission sets assigned, then return Missing, if there are more permission sets assigned, return Additional, else return No Change. I need to implement this using either Flow or Apex. 
  • The final output should give me the userID, the permission sets assigned to them and Missing/Additional/No change
Till now I have been doing this manually by querying the PermissionSetAssignment object, then retrieving the Assignee details and the permission sets assigned to the assignee, then manually checking.
 
Thank you