Activity Forums Salesforce® Discussions What are the test class best approaches in Salesforce?

  • MOHIT

    Member
    February 23, 2020 at 5:05 am

    To get the minimum required 75% test coverage, all you have to do is make Salesforce run the code that you want to test.

    Do not put (seeAllData = true) in test class otherwise, use it for exceptional cases.

    Use @isTest at the Top for all the test classes.

    Test in bulk: Test to see if your code can run on 200 records at once. This is the maximum number of records that can be evaluated in a single trigger by Salesforce.Don’t worry about this one too much for now, since we’ll be talking more about it in our Governor Limits chapter! It’s possible that your code runs fine if a single Contact goes through your trigger – but it might break if 200 Contacts are evaluated in your trigger!

    Avoid Using Hard Coding Ids anywhere in test Class or any apex class.

    Use System.assertEquals() to see if your code has the expected outcomes: for example, if your code changes a Contact’s education to ‘Graduate’, make sure it actually did by doing System.assertEquals(‘Graduate’, myContact.education__c);

    Use Test.startTest() and Test.stopTest() statement to increase Governor Limits of your test code.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos