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
Swaroopa Akula 2Swaroopa Akula 2 

delay in responses to the cases because of the trigger

I have a trigger and handler which is used to get the auto entitlement name select in the case.

Here is the code. Please help me on why i am having process delay issues. Thanks in advance!

Trigger:


trigger CaseUpdatedTrigger on Case (before insert, before update) {
       
    if(trigger.isBefore){
        
        if(trigger.isInsert){
        
        CaseUpdatedTriggerHandler.handleBeforInsert(trigger.new);
        }
        
        if(trigger.isUpdate){
       
         CaseUpdatedTriggerHandler.handleBeforUpdate(trigger.new);
        }
        
    }
}

Handler:

public class CaseUpdatedTriggerHandler {
    
    public static void handleBeforInsert(List<Case> newCaseList){
        getCaseEntilementID(newCaseList);  
    }
    
    public static void handleBeforUpdate(List<Case> newCaseList){
        getCaseEntilementID(newCaseList);
    }
    
    //Helper method to get EntilementID based on case priority
    private Static void getCaseEntilementID(List<Case> caseList){
        
        Set<Id> acctIds = new Set<Id>();
        for (Case c : caseList) {
            acctIds.add(c.AccountId);
        }
        
        List <Entitlement> entls = [Select e.StartDate, e.Id, e.EndDate, 
                    e.AccountId
                    From Entitlement e
                    Where e.AccountId in :acctIds AND e.StartDate <= Today];                  
        if(entls.isEmpty()==false){
            for(Case c : caseList){
               if(c.EntitlementId == null && c.AccountId != null){
                    for(Entitlement e:entls){
                       if(e.AccountId==c.AccountId){
                            // entilementID = e.Id;
                            c.EntitlementId  = e.Id; 
                            break;
                        }
                    } 
                }
            } 
        }
    }
}
ANUTEJANUTEJ (Salesforce Developers) 
Hi Swaroopa,

Since in both of them you are  calling the same function have you tried putting the logic part in the trigger and see how long it is taking and can you try performing the same logic in anonymus window and see if there is a delay still present and if so you can set up debug logs to see where the delay is occuring.

In case if the above information was helpful for your issue can you please close the thread and mark this as the best answer so that it can be useful for others in the future and also helps in keeping our community clean.

Regards,
Anutej