+ Start a Discussion
Cris9931Cris9931 

error when i try to call a class in my trigger

Hi! I have created a trigger:

trigger SIG_permissionToEditAdminTasks on SIG_Administrative_Task__c (before update) {
       

         SVMXC__Service_Order__c queueOwner = new SVMXC__Service_Order__c();
        ApexPages.StandardController sc = new ApexPages.StandardController(queueOwner);
       SIG_QueueOwnerUpdate classQueue = new SIG_QueueOwnerUpdate(sc);
         
         
         
          public Set<String> memberIds = new Set<String>();
          String currentUserID = UserInfo.getUserId();
          SIG_Administrative_Task__c admTask = new SIG_Administrative_Task__c();
          
          
     
      //fetch the id of the creator of the record <start>
           Set<String> ownerIds = new Set<String>();
        for (SIG_Administrative_Task__c record : Trigger.New) {
            ownerIds.add(record.OwnerId);
             
        }
        
      // <end>
        
        List<Group> groups = [SELECT Id, (SELECT Id, UserOrGroupId FROM GroupMembers) FROM Group WHERE Id =: ownerIds];
        System.debug('####groups' + groups);    
        
          
         Set<String> memberIdsByGroupId = new Set <String>();
   
        //fetch the id's of the users from the the current owner queue  <start>
        for (Group groupRec : groups) {
         
            for (GroupMember member : groupRec.GroupMembers) {
                memberIds.add(member.UserOrGroupId);
            }
              
        }
        // <end>
       system.debug('memberIds123'+memberIds);

         for (SIG_Administrative_Task__c record : Trigger.New) {
            if((memberIds.contains(currentUserID) || record.createdById == UserInfo.getUserId() || record.OwnerID == UserInfo.getUserId() ))
            {
           
            }
            else
            {
               record.addError('You need to be the owner or to be inside of a queue to edit an Admin Task');
            }
        }
    

}

On this line I am trying to call a class in my trigger:

ApexPages.StandardController sc = new ApexPages.StandardController(queueOwner);
 SIG_QueueOwnerUpdate classQueue = new SIG_QueueOwnerUpdate(sc);


Everything looks fine.. but when I try to activate my trigger and do an update on a record i have this error:

User-added imageWhen i took a look in my class, line 73 this is what I see:

User-added imageHow can I call my class without getting this error?

Best Answer chosen by Cris9931
Cris9931Cris9931
I found a workaround on this guys! Thanks for all the answers.

All Answers

ShirishaShirisha (Salesforce Developers) 
Hi Sarah,

Greetings!

The root cause of the issue is because of the data which is coming as null when you are trying to call the list.So,I would suggest you to check the SOQL queries and see,if they are returning any records and add the logic mentioned in the below doc:

https://help.salesforce.com/articleView?id=000327918&type=1&mode=1

Kindly let me know if it helps you and close your query by marking it as best answer so that it can help others in the future.

Warm Regards,
Shirisha Pathuri
AnudeepAnudeep (Salesforce Developers) 
Hi Sarah, 

In general, when calling a controller inside apex trigger, the object that is passed is the object that the trigger is supposed to be fired on like the example below and I have always seen it that way
trigger SendTrainingConfirmationTrigger on Course_Sale__c (after insert, after update) {
  
    for (Course_Sale__c cs : Trigger.new) {
      if (cs.AttachmentId__c != null) && (cs.Send_Confirmation_Automatically__c == True) && (cs.has_confirmation_been_sent__c == FALSE)
      {
            ApexPages.StandardController sc = new ApexPages.StandardController(cs);
			TrainingConfirmationSend obj = new TrainingConfirmationSend(sc);
                }    
    }
}
I could be wrong but I am suspecting that to be the cause of the issue

Anudeep
Cris9931Cris9931
I found a workaround on this guys! Thanks for all the answers.
This was selected as the best answer