0

I'm running a unit test in developer console and in setup and I appear to be getting two different results. Within the dev console, my unit tests appear to be passing. But when I run the tests in setup, the unit tests fail.

    @isTest 
    static void AssignCaseToIntegrationHCM() {

    String testCase1Owner, testCase2Owner, testCase3Owner;

    Test.startTest();

    Case testCase1 = [SELECT Id, OwnerId FROM Case WHERE Subject = :CASE_1_SUBJECT];
    Case testCase2 = [SELECT Id, OwnerId FROM Case WHERE Subject = :CASE_2_SUBJECT];
    Case testCase3 = [SELECT Id, OwnerId FROM Case WHERE Subject = :CASE_3_SUBJECT];

    testCase1Owner = getGroupNameById(testCase1.ownerid);
    testCase2Owner = getGroupNameById(testCase2.ownerid);
    testCase3Owner = getGroupNameById(testCase3.ownerid);

    Test.stopTest();

    System.assertEquals(HCM_QUEUE, testCase1Owner, 'Failed to assign case to HCM Queue');
    System.assertEquals(HCM_QUEUE, testCase2Owner, 'Failed to assign case to HCM Queue');
    System.assertEquals(HCM_QUEUE, testCase3Owner, 'Failed to assign case to HCM Queue');
 }

    private static String getGroupNameById(Id groupdId){
        return [SELECT Name FROM Group WHERE ID  = :groupdId LIMIT 1].name;
   }

For some reason, I get a queryexception when I call the getGroupByName method:

System.QueryException: List has no rows for assignment to SObject

Thoughts?

0

See answer: Case Owner changing upon case insert (all case triggers are inactive)

TL;DR - execution context is different, needed to use DML opts to ensure cases are routed correctly when running tests through setup

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.