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 

Trigger to Create an Entitlement

I found a trigger in the Developer Cookbook. The trigger looks at a case being entered to check if an entitlement has been assigned to the case. If the case has no entitlement then it checks the contact or account associated to see if they have an entitlement. I love the trigger however I need it to do one other function. If no entitlement is found then create an entitlement for the Account associated. Please help on this as it is holding us up in deploying the Entitlement process.



trigger defaultEntitlement on Case (Before Insert, Before Update) {
   If the Entitlement Name is not set then, check to see if the Contact on the Case has an active Entitlement
    and select the first one.  If not then check to see if the Account on the Case has an active Entitlement.
   List<Id> contactIds = new List<Id>();
   List<Id> acctIds = new List<Id>();
   for (Case c:{
      if (c.EntitlementId == null && c.ContactId!= null && c.AccountId!= null){
   if(contactIds.isEmpty()==false || acctIds.isEmpty()==false){
      /* Added check for active entitlement */
      List <EntitlementContact> entlContacts = [Select e.EntitlementId,e.ContactId,e.Entitlement.AssetId From EntitlementContact e
                                                Where e.ContactId in:contactIds
                                                And e.Entitlement.EndDate >= Today And e.Entitlement.StartDate <= Today];
         for(Case c:{
            if(c.EntitlementId == null && c.ContactId!= null){
               for(EntitlementContact ec:entlContacts){
                     c.EntitlementId = ec.EntitlementId;
                     if(c.AssetId==null && ec.Entitlement.AssetId!=null)
               } // end for
         } // end for
      } else{
         List <Entitlement> entls = [Select e.StartDate, e.Id, e.EndDate, e.AccountId, e.AssetId
                                     From Entitlement e
                                     Where e.AccountId in:acctIds And e.EndDate >= Today And e.StartDate <= Today];
            for(Case c:{
               if(c.EntitlementId == null && c.AccountId!= null){
                  for(Entitlement e:entls){
                        c.EntitlementId = e.Id;
                        if(c.AssetId==null && e.AssetId!=null)
                  } // end for
            } // end for
   } // end if(contactIds.isEmpty()==false)



Please let me know what other information is needed. I really could use some help trying to solve it.





I can try to help you with this one. But I will need more information on this.

If possible we can connect through gtalk/skype then we can discuss.


My gtalk id is