3

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

1 Answer 1

2

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.

2
  • Is my answer serves your purpose? Aug 14, 2017 at 13:29
  • is this mentioned anywhere in the documentation? Just want to make sure if we are following best practices
    – apz
    Apr 3 at 13:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .