0

Here is the code:

for(User u : usrList){
    usersRecordToUpdateId.add(u.id);

    if(!usersRecordToUpdateId.isEmpty()){
        Map<Id, List<String>> esfgroup = new Map<Id, List<String>>();
        List<String> newgrouplist = new List<String>();
        List<GroupMember> groupMemberRecList = [select id, GroupId, Group.Name, UserOrGroupId, Group.developerName from GroupMember where UserOrGroupId in :usersRecordToUpdateId WITH SECURITY_ENFORCED LIMIT 1];

and I getting error while I am querying in groupMemberRecList

Can someone suggest how to resolve it.

1 Answer 1

3

Seems Like You have groupMemberRecList query inside a loop and that is not a good practise in SF, Take the query out of the loop

refer as below

List<Id> usersRecordToUpdateId = new List<Id>();

Map<Id,List<String>> esfgroup = new Map<Id,List<String>>();

List<String> newgrouplist = new List<String>();

for(User u : usrList){
    usersRecordToUpdateId.add(u.id);
}

if(!usersRecordToUpdateId.isEmpty()){
   
    List<GroupMember> groupMemberRecList=[select id,GroupId,Group.Name,UserOrGroupId, Group.developerName from GroupMember where UserOrGroupId in :usersRecordToUpdateId WITH SECURITY_ENFORCED LIMIT 1];
}

1
  • @user131940 why did you removed the best answer ?
    – Aman Patil
    Commented Apr 21, 2023 at 7:20

You must log in to answer this question.