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
StaciStaci 

business hours with entitlement trigger

Hi.  I have my entitlements automatically getting attached to cases with an apex trigger.  Each milestone (depending on priority and a checkbox) have different business hours.  When I create a case, the default business hours are getting added instead.  How do I fix this in the trigger?
 
trigger CW_DefaultEntitlement on Case (Before Insert, Before Update) {
    
    List<Id> acctIds = new List<Id>();
    for(Case c: Trigger.new){
    if(String.isNotBlank(c.AccountId)){
        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.EndDate >= Today And e.StartDate <= Today];
        if(entls.isEmpty()==false){
            for(Case c : Trigger.new){
                if(c.EntitlementId == null && c.AccountId != null){
                    for(Entitlement e:entls){
                        if(e.AccountId==c.AccountId){
                            c.EntitlementId = e.Id;
                            
                        }
                    }
                }
            }
        }
    }

 
Best Answer chosen by Staci
sharathchandra thukkanisharathchandra thukkani
the business hours which you have set at the entitlement process level remove that, it will override the default business hours which are set at the milestone level.

All Answers

sharathchandra thukkanisharathchandra thukkani
at the milestone level when you are creating the entitlement process you have option to select the business hour that will solve the issue
StaciStaci
@sharathchandra thukkani  I have that set already.  The trigger is not using it.  Its defaulting to the default business hours
sharathchandra thukkanisharathchandra thukkani
the business hours which you have set at the entitlement process level remove that, it will override the default business hours which are set at the milestone level.
This was selected as the best answer
StaciStaci
Thanks @Sharathchandra thukkani  I removed the bussiness hours from the entitlement process and it working now!