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
Kevin LanguedocKevin Languedoc 

Update Case Owner

I have a picklist field that has a list of the Queue groups as values. When the case initiator creates a case, they must either assign it to one of the groups in the Queue or keep it. If they assign to a Queue, the owner field must be updated with this new value and an e-mail must be sent to the new owners.

When I deploy to sandbox, which is successful, I get this error message from the APex editor in the sandbox


Error: Compile Error: Variable does not exist: Trigger at line 5 column 18



trigger UpdateCaseOwner on Case (before update) {
    //select Id, Name from Group where Name = 'QA' and Type = 'Queue'
    
    
    for(Case c : Trigger.new()){
        
        List<Group> qid = [select Id from Group where Name = : c.CaseAssignedOwner__c and Type = 'Queue'];
      for(Group g : qid){
            c.OwnerId = g.id;
        }
        
       
    }
      
}
Best Answer chosen by Kevin Languedoc
Pankaj_GanwaniPankaj_Ganwani
Hi,

In for loop, you should be using Trigger.new instead of using Trigger.new() since it is not a function.

trigger UpdateCaseOwner on Case (before update) {
    //select Id, Name from Group where Name = 'QA' and Type = 'Queue'
    
    
    for(Case c : Trigger.new){
        
        List<Group> qid = [select Id from Group where Name = : c.CaseAssignedOwner__c and Type = 'Queue'];
      for(Group g : qid){
            c.OwnerId = g.id;
        }
        
       
    }
      
}

All Answers

Pankaj_GanwaniPankaj_Ganwani
Hi,

In for loop, you should be using Trigger.new instead of using Trigger.new() since it is not a function.

trigger UpdateCaseOwner on Case (before update) {
    //select Id, Name from Group where Name = 'QA' and Type = 'Queue'
    
    
    for(Case c : Trigger.new){
        
        List<Group> qid = [select Id from Group where Name = : c.CaseAssignedOwner__c and Type = 'Queue'];
      for(Group g : qid){
            c.OwnerId = g.id;
        }
        
       
    }
      
}
This was selected as the best answer
Kevin LanguedocKevin Languedoc
Thanks