Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- trigger caseOwnerUpdate on Case (before insert,before update,after update)
- if(Trigger.isBefore && Trigger.isUpdate)
- {
- System.debug('entered if condition');
- for(Case c : Trigger.new)
- {
- System.debug('Updating logic');
- List<Group> qid = [select Id from Group where Name = : c.Assignment_Group__c and Type = 'Queue'];
- for(Group g : qid)
- {
- c.OwnerId = g.id;
- System.debug('updated');
- }
- }
- }
- List<Case> updateCS = new List<Case>();
- Map<Id,Case> cases = new Map<Id,Case>();
- for (Case cs : Trigger.new)
- {
- if(Trigger.isUpdate) {
- System.debug('>>>>> Owner ID: '+cs.ownerId+' Temp Owner ID: '+cs.TempOwnerId__c);
- if(cs.TempOwnerId__c <> null && cs.TempOwnerId__c <> '') {
- if(cs.OwnerId <> cs.TempOwnerId__c) {
- cases.put(cs.id,cs);
- }
- }
- }
- }
- if (cases.isEmpty()) return;
- for (Case cs : [SELECT OwnerId,TempOwnerId__c FROM Case WHERE id in :cases.keySet()]) {
- cs.OwnerId = cases.get(cs.Id).TempOwnerId__c;
- cs.TempOwnerId__c = 'SKIP'; //flag to stop infinite loop upon update
- updateCS.add(cs);
- }
- System.debug('>>>>>Update Cases: '+updateCS);
- //
- //Update last assignment for Assignment Group in batch
- //
- if (updateCS.size()>0) {
- try {
- update updateCS;
- } catch (Exception e){
- }
- }
- }
- if(Trigger.isBefore && Trigger.isUpdate)
- {
- for(Case c : Trigger.new)
- {
- if(c.Assignment_Group__c=='Tech Support'||c.Assignment_Group__c=='GD-IT'||c.Assignment_Group__c=='App-Support'||c.Assignment_Group__c=='GD-RM'||c.Assignment_Group__c=='GD-DB'||c.Assignment_Group__c=='Dev-Ops'||c.Assignment_Group__c=='App-Management'||c.Assignment_Group__c=='PDT-DS-Engg'||c.Assignment_Group__c=='PDT-US-Engg')
- {
- c.Group_Manager_Email__c = 'sgaware148@gmail.com'; c.Escalation_Level_2_Email__c ='sgaware148@gmail.com'; c.Escalation_Level_3_Email__c='sgaware148@gmail.com';
- }
- }
- }
Add Comment
Please, Sign In to add comment