1

I'm working on a trigger that will add an entitlement to an account after the account is inserted. In addition, the entitlement that is created will also have an SLA process ID associated with it. While writing some tests, I noticed that I was able to retrieve the SLAProcess without using the (seeAllData =true) annotation.

Here's a snippet of the apex class:

        sla = [SELECT Id, NAME FROM Slaprocess WHERE IsActive = true LIMIT 1];

        for(Account a : accounts){
            Entitlement e = new Entitlement();
            e.SlaProcessId  = sla.id;
            e.AccountId     = a.id;
            e.Name          = ENTITLEMENT_NAME;
            entitlements.add(e);
        }

        insert entitlements;

Since we cant insert SLA processes through Apex, I'm curious as to how that query brought back all SLA process ID's in my org.

Any thoughts on why this is?

0

This is by design. Salesforce doesn't allow us to create Entitlement Process (SLAProcess) from test class.

So, as a pre-caution during deployment, you need to create entitlement process in new org or production and then you will run the test classes, otherwise it will fail.

Update:

DML operation INSERT not allowed on SlaProcess.

Refer this my answer here How to set Entitlement Process Name in a Test?

5
  • If I run "SELECT Id FROM SlaProcess" in my Dev org I get ->sObject type 'SlaProcess' is not supported. (tooling API is unchecked). Do you know why is that?
    – SfdcBat
    Nov 9 '17 at 15:38
  • did you activate Entitlement Settings? Nov 9 '17 at 15:47
  • Nope. It works now :)
    – SfdcBat
    Nov 9 '17 at 15:51
  • Hey @SantanuBoral, So just to be clear, being able to query SLA process without seeAllData is working as designed? Have you come across any documentation from SFDC that states that? Seems odd that this object is accessible in test
    – Brohan
    Nov 9 '17 at 19:10
  • refer my updated answer Nov 10 '17 at 4:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.