According to datamodel Entitlement to Account is
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,
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>();
Entitlement newRecordEnt = new Entitlement();
newRecordEnt.Name = acct.Name + ' Entitlement'; //whatever suitable name
newRecordEnt.SlaProcessId = entitlementProcessId;
newRecordEnt.AccountId = acct.Id;
//insert more attributes if needed
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.