I have written a Trigger which links an Entitlement with the Case based on the RecordType, Category and SubCategory. Now I am looking to get the name of Entitlement Process into the System.assert to verify the system is picking the correct one for the result expected and actual.

public static void getAllXXXX(List<SObject> newSobjs){


         Map<String,Id> entitlementMap = new Map<String,Id>();
         for(Entitlement entMap : [Select Id,Name from Entitlement where Name IN :entilementNames]){
                entitlementMap.put(entMap.Name, entMap.Id); // line-28

Now when I executing the my test class line-28 is not executing. When I checked in the logs entilementNames value coming is correct, and when I execute Select Id,Name from Entitlement where Name IN :entilementNames manually results are comming, but through code its not comming whats the issue ?


        Case cs = new Case();
        cs.RecordTypeId = getRecordType();
        cs.Category__c = 'TTTT';
        cs.SubCategory__c = 'AAAAA';
        cs.Status = 'New';
        cs.Origin = 'Web';
        cs.ProjectName__c = 'XXX';

        List<Case> cases = new List<Case>();
        insert cases;


        List<Id> csIds = new List<Id>();
        for(Case c : cases){

        List<Case> caList = [SELECT CaseNumber,EntitlementId,RecordTypeId FROM Case WHERE Id= :csIds];        
        System.debug('Case Details :: '+caList);

        List<String> entitlementIds = new List<String>();
        for(Case c : caList){

        List<Entitlement> entitlements = [SELECT Name FROM Entitlement WHERE Id= :entitlementIds];

        Set<String> entitlementNames = new Set<String>();
        for(Entitlement e : entitlements){

        System.assert(cases != null);
        System.assert(entitlements != null);
        System.assertEquals( entitlementNames.contains('PPPP'));


How can I checked the value of entitlementname in assert ? Why line-28 not executing ?


1 Answer 1


Issue is your code is you need to create Entitlement records and then link with Case.

//create Account
Account acct = new Account(Name='Test1');
insert Acct;

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

//create Entitlement Record
Entitlement ent = new Entitlement (AccountId=Acct.Id, SLAProcessId = entitlementProcessId, Name = 'Test Entitlement');
insert ent;

Case cs = new Case();
cs.RecordTypeId = getRecordType();
cs.ELC_Category__c = 'TTTT';
cs.ELC_SubCategory__c = 'AAAAA';
cs.Status = 'New';
cs.Origin = 'Web';
cs.ELC_ProjectName__c = 'XXX';
cs.EntitlementId =  ent.Id;
insert cs;
  • Take the value which you have configured at your org, because this record cannot be created in test class Jul 28, 2017 at 21:54
  • I think you have defined as SLA Tracx Jul 28, 2017 at 22:00
  • Entitlement name should match what you have declare in metadata type. So, prepare the data accordingly Jul 28, 2017 at 22:04
  • I am getting error : System.QueryException: List has no rows for assignment to SObject for //retrieve Default Entitlement Process information
    – user46657
    Jul 28, 2017 at 22:11
  • I told you earlier you need to fetch record of Entitlement Process and based on that create entitlement Jul 28, 2017 at 22:13

You must log in to answer this question.