0

I have a trigger and a test class that produces 51% code coverage of the trigger (>0%) when run as a test. If I validate the trigger and test class I get no test failures but I get 'Code Coverage Error'. I run a Debug log while the validate is running and I can see the trigger being fired during the validate. I can see debug statements that prove that at least a dozen lines of code in the trigger are being executed during the validate.

How is possible that I still get Code Coverage Error when I can see the code being executed?

Test code:

    Test.startTest();
    lstAccounts = new List<Account> {
            new Account(Name = 'Test Contractor 3', RecordTypeId = idRTContractor, Main_Office__c = false, OrganizationId__c = '5555'),
            new Account(Name = 'Test Account')
    };
    insert lstAccounts;
    lstAccounts[1].Programs_Not_Interested_In__c = 'ABC';
    update lstAccounts;

    // The following should not have any effect as the trigger would've been by the insert
    database.executeBatch(new BulkFixup('Account'));
    Test.stopTest();

Trigger code:

trigger CopyOrgWideDataOnUpdate on Account (before update) {
...
Set<String> stOrgIds = mpOrgIdToChangedFields.keySet();
Set<Id> stIds = Trigger.newMap.keySet();
String query = 'SELECT Id, OrganizationId__c, ';
query += String.join(new List<String>(changedFieldSet), ', ');
query += ' FROM Account WHERE OrganizationId__c IN :stOrgIds AND Id NOT IN :stIds';
System.debug('Query: ' + query);
ChildAccounts = Database.query(query);

Debug Log Showing execution:

09:22:32.501 (2609240221)|CODE_UNIT_STARTED|[EXTERNAL]|01qE0000000N1uJ|CopyOrgWideDataOnUpdate on Account trigger event BeforeUpdate for [001Q0000019Lwe3, 001Q0000019Lwe4]
09:22:32.501 (2615546437)|USER_DEBUG|[23]|DEBUG|TEST
09:22:32.501 (2626059685)|USER_DEBUG|[23]|DEBUG|TEST
09:22:32.501 (2637231423)|USER_DEBUG|[95]|DEBUG|Query: SELECT Id, OrganizationId__c, Benji_Status__c, Benji_Activated_Date__c FROM Account WHERE OrganizationId__c IN :stOrgIds AND Id NOT IN :stIds
09:22:32.501 (2637719625)|SOQL_EXECUTE_BEGIN|[96]|Aggregations:0|SELECT Id, OrganizationId__c, Benji_Status__c, Benji_Activated_Date__c FROM Account WHERE OrganizationId__c IN :stOrgIds AND Id NOT IN :stIds
09:22:32.501 (2643427661)|SOQL_EXECUTE_END|[96]|Rows:0
09:22:32.643 (2643601790)|CUMULATIVE_LIMIT_USAGE
09:22:32.643 (2643601790)|LIMIT_USAGE_FOR_NS|(default)|

The debug line 'Query:' does not appear in the version of the code currently in the environment therefore this also acts as evidence that the new test and trigger code are included in the changeset.

0

1 Answer 1

1

I have now restructured my code and the problem no longer exhibits. Don't know what the cause or solution was. I was obviously doing something funky but it is now lost to antiquity.

You must log in to answer this question.

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