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
Victor19Victor19 

After Update Trigger - Error

Hi,

I have set up an after update trigger for a dynamic approval process on my custom object (TestObj).
However I am getting a save error:  Initial term of field expression must be a concrete sObject: List<Group> (Highlighted in Red)

trigger Test_ApprovalProcess on TestObj__c (after update) {
    List<String> QNames = new List<String>();
    
    //Retreiving the Queue_Name__c from each TestObj__c record and populating the list
   
    for(TestObj__c test : Trigger.new){
        String QName = test.Queue_Name__c;
         QNames.add(QName);
System.debug('zz QNames: ' + QNames);
    }
    
    Map<Id, Id> groupIDMap = new Map<Id, Id>();
    List<String> idList = new List<String>();
    List<group> gList = [SELECT (select userOrGroupId from groupMembers)
                FROM group
                WHERE name = :QNames];   //use the referenced name field from the EFR_Funding record to make it dynamic
    for (GroupMember gm : gList.groupMembers){
        idList.add(gm.userOrGroupId);
 System.debug('zz ids: ' + idList);   
    }

    //Submit records for approval based on the condition below
    for(TestObj__c test1: Trigger.new){
        if(test1.Approval_Status__c == 'Approved by Manager'){
            Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();
            req1.setComments('Submitting request for Approval.');
            req1.setObjectId(ef.id);
            req1.setNextApproverIds(idList);
            Approval.ProcessResult result = Approval.process(req1);
            System.assert(result.isSuccess());
            System.assertEquals('Pending', result.getInstanceStatus(), 'Instance Status'+result.getInstanceStatus());
        }
    }
}

 

Can someone please point out or correct my code.

 

Thanks!

Dhaval PanchalDhaval Panchal

Instead of,

 


    for (GroupMember gm : gList.groupMembers){
        idList.add(gm.userOrGroupId);
 System.debug('zz ids: ' + idList);   
    }

 

use below

 

if(gList.size()>0){
	for(Group grp:gList){
		if(grp.groupMembers.size()>0){
			for (GroupMember gm : grp.groupMembers){
				idList.add(gm.userOrGroupId);
				System.debug('zz ids: ' + idList);   
			}
		}
	}
}

 

Abhi_TripathiAbhi_Tripathi

Have you tried 

 

   //Loop

   for (GroupMember gm : gList){

 

            //Add to list       

 

            idList.add(gm.userOrGroupId);

           System.debug('zz ids: ' + idList);   
 }

 

Hope this works