1

I want to set default entitlement process for all the accounts which doesn't have other entitlement process. I setup new Entitlement Process with milestones ("Default Entitlement"), and understand that the rest should be done with trigger, which is fine.

What I don't understand is whether the trigger should create Entitlement record (linkage between the Account to Entitlement Process)?

If it does require, I don't see the benefit for having a trigger? I can use dataloader for creating Entitlement records for all the accounts with no other Entitlement.

| improve this question | | | | |
2

According to datamodel Entitlement to Account is Master-Detail relationship.

If you want to associate default Entitlement Processto any account, you have to create a Entitlement record for that Account and then only you can associate the Process.

There are 2 approaches to solve this requirement.

Approach 1 (execute script from Developer Console)

a. Create a rollup summary field (say Count_of_Entitlements__c) with count of Entitlements the account has.

b. Search for those Accounts where Count_of_Entitlements__c = 0.

c. Loop through the accounts and create a list of Entitlements to be added.

d. Finally insert List of Entitlements.

Map<Id,Account> accountsWithoutEnt = new Map<Id, Account>(
                                       [SELECT Id, Name, 
                                        Count_of_Entitlements__c 
                                        FROM Account 
                                        WHERE Count_of_Entitlements__c = 0]);

//retrieve Default Entitlement Process information
    Id entitlementProcessId = [SELECT Id FROM SlaProcess 
                               WHERE SObjectType = 'Case' 
                               AND Name='<Entitlement Process Name>'].Id;

    System.debug('entitlementProcessId=' + entitlementProcessId);

    //loop through the map of records and create entitlement record
    List<Entitlement> lstEntitlement = new List<Entitlement>();
    for(Account acct:accountsWithoutEnt.values())
    {
        Entitlement newRecordEnt = new Entitlement();
        newRecordEnt.Name = acct.Name + ' Entitlement'; //whatever suitable name
        newRecordEnt.SlaProcessId = entitlementProcessId;
        newRecordEnt.AccountId = acct.Id;
        //insert more attributes if needed

        lstEntitlement.add(newRecordEnt);
    }

    insert lstEntitlement;

Approach 2 (Option for using dataloader)

a. Create an extract from reports where Accounts with no Entitlements.

b. Create a .csv file to create entitlements and associate with the account.

I would prefer the Approach 1 where this small script will serve this purpose.

You can take your suitable approach which ever suits you best.

Moreover, trigger is not needed here.

| improve this answer | | | | |
  • Thanks. I would probably use the second approach. General idea was to have 1 Entitlement Process, and associate it to Case if the related account doesn't have any Entitlement. I wanted to avoid creating ~8000 Entitlement (1 record per each account), now I understand it's require. – Liron C Nov 26 '16 at 19:04
  • If any answer solves your requirement, please close it. – Santanu Boral Nov 26 '16 at 19:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.