[SalesForce] Case default entitlement process

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.

Best Answer

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.

Related Topic