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

Entitlement ID

We've enabled our entitlement module and we need to be able to auto-generate an entitlement id when a new account is created.  Does anyone know how this should be written, looks as if the only way to set this up would be through Apex. 


Currently our feed brings over external account information and if that account doesn't already exist, it creates a new account in Salesforce (ID field in the Accounts object).  Ideally we're trying to figure out how an associated entitlement id could be created with the Account ID, generating an entitlement object (Entitlement_c) with the same name as the Account name. 


If anyone has tried this approach or if more details are needed, please let me know.

I am currently looking to do the same expect a little different. I found this code in the Developer Cookbook that when a case is created will check the contact and account for an associated entitlement then assign the entitlement to the case. I am trying to add to the trigger to have it create the entitlement for the account if one is not found but only. I have a seperate post asking for help. Here is the trigger I found:



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)




I am also looking for kind of the same trigger : auto create an entitlement on an account update. The code should not be complicated but I don't know how to write it.


Orion, the trigger you showis used to link a case automatically to an entitlement, in case the entitlement already exists, right ? I may be wrong but, this trigger could be kept in a separate trigger ?