Following Salesforce docs, I createad a class that assignes milestones to cases. If the account has an entitlment, then it creates milestones. The class works super!.
The problem is the unitTest class this is the structure:
- Account created, then 'Insert' of accounts;
- Contact created and linked to Accounts, then 'Insert contacts' and 'Update Accounts'
- Entitlements created, SLAProcessid assigned (Yes the Process is Active), StartDate and EndDate assigned as well as business hours and accountId;(see code snippet below). Then 'Insert entitlements' and 'update accounts';
If you look at the screenshot the e.status is 'null' and I cannot figure out why. Any help? Thank you, GC
for (Account acc : accounts) {
Entitlement accountEntitlment = new Entitlement();
accountEntitlment.AccountId = acc.Id;
accountEntitlment.Account = acc;
accountEntitlment.SlaProcessId = slaProcessesId[0].Id;
accountEntitlment.Name = 'TestSLA ' + acc.Name;
accountEntitlment.StartDate = Date.newInstance(2022, 1, 1);
accountEntitlment.EndDate = Date.newInstance(2041, 4, 12);
accountEntitlment.BusinessHours = businesshoursId;
accountEntitlment.BusinessHoursId = businesshoursId.Id;
accountEntitlments.add(accountEntitlment);
}
insert accountEntitlments;
update accounts;
System.debug('GC*** Created ENTITLEMENTS ' + accountEntitlments);
for (Entitlement e : accountEntitlments) {
System.debug('GC*** Entitlement active? ' + e.Status);
System.debug(
'GC*** Entitlement process: ' +
e.SlaProcessId +
'\n' +
'Start: ' +
e.StartDate +
'\n END DATE ' +
e.EndDate +
'\n Account: ' +
e.Account.Name
);
}