This trigger creates an entitlement for every account that meets certain criteria.
I have read the triggers process records in chunks of 200 but I am not understanding why the trigger below only creates 200 entitlements records even when I am inserting 250 accounts.
It seems like only the first chunk is processed by the trigger. I don't see any errors in the logs. Thanks in advance.
This is part of the code.
UPDATE:I have added the 2 lines of code at the beginning that are causing the issue.
if(util1.accountEntitlementAssignment) return;
util1.accountEntitlementAssignment=true;
for(Entitlement ent: [Select Id,AccountId from Entitlement Where Status='Active']){
AccsWithEnt.add(ent.AccountId);
}
for (Account acc : trigger.new) {
if(acc.test_Subscription_Type__c=='testEnterprise'){
//Only create entitlements for accounts that don't have one
if(!AccsWithEnt.contains(acc.id)){
createentitlement.add(new Entitlement (
Name='Enterprise Entitlement',
AccountId=acc.Id,
StartDate=todayDate,
EndDate=todayDate.addYears(5),
SlaProcessId=slaMap.get('Enterprise Entitlement').Id));
}
}
}
Insert createentitlement;
This is how I am testing it
List<Account> accs=new List<Account>();
for(Integer i=0;i<250;i++){
accs.add(new Account(
name='test'+i,
test_Subscription_Type__c='testEnterprise'));
}
insert accs;
}