You need to sign in to do that
Don't have an account?
Staci
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; } } } } } }
All Answers