[SalesForce] How to set Entitlement Process Name in a Test

I'm trying to create a test class for a class that assigns a specific Entitlement process to accounts that have an empty lookup field. The problem I'm facing is that I'm receiving an error when trying to write the SlaProcess.name Value.

My Class:

public class Asignar_SLA {
    public static void sla(){
        SlaProcess sla = [Select id from SlaProcess Where Name='SLA Tracx'];
        List<Account> Cuentas = [Select Id from account where Entitlement__c=Null];
        for(Account acc:Cuentas){
            Entitlement SL  = new Entitlement();
            sl.SlaProcessId = sla.id;
            sl.AccountId    = acc.id;
            sl.Name         = 'SLA';
            insert sl;
            }
    }

}

My test Class so far:

@istest public class Asignar_SLA_isTest {
     public static void Test_SLA(){
         SlaProcess SLA = new SlaProcess();
         sla.Name = 'Sla Tracx';
         Account acc = new Account();



    }

}

The error I'm getting:

Field is not writeable: SlaProcess.Name

Best Answer

DML operation INSERT not allowed on SlaProcess.

So, you need to expose your organization data at your test method.

  1. You need to use seeAllData=true in the test method to retrieve SlaProcess information.

  2. You can make configurable to use the name from custom settings or custom label.

  3. Before deploying the test class you need to make sure SlaProcess exist at Production.

Related Topic