Getting Started


Unit Test for Apex Helper


Salesforce enforce any code deployed to production has been tested and a good coverage percentage as result. The way to test this is actually with an apex class specially designed to test your apex helper classes.

The following is what we should do in order to test the previous AccountNameChanger apex class considering that the Atarc Process Setting record exists in the org where the test runs:


/*
* Created By: anyei
* Created Date : 2020-03-02
* Tested Class : AccountNameChanger
* Tested ATARC Process: ChangeAccountName
*/ 
@isTest
public class AccountNameChangerTest {
    
    @testsetup static void setup(){
        ATARC_Global_Setting__c aSetting = new ATARC_Global_Setting__c(debug__c = true, LoopLimit__c=1);
        insert aSetting;

    }


    //test the functionality
    @istest static void NameChangesWhenNewAccount(){
        
        Account acc = new Account(Name='Hey');

        test.starttest();
        insert acc;
        test.stoptest();
        
        acc = [select Name from Account where Id=:acc.Id];
        system.assert(acc.Name == 'Yo', 'Expected "Yo" actual: '+acc.Name);
    }
    
   
}
  
Next Steps - Tutorials