Play Games

Search This Blog

Showing posts with label How to skip piece of code in Apex Class from running while associated test class is running in Salesforce. Show all posts
Showing posts with label How to skip piece of code in Apex Class from running while associated test class is running in Salesforce. Show all posts

Friday, June 16, 2017

How to skip piece of code in Apex Class from running while associated test class is running in Salesforce

Solution: Use if(!Test.isRunningTest()) {} to skip piece of code.
Example:
public void validate() {
if(!Test.isRunningTest()) {
Account objAccount  = new Account();
objAccount.name ='Test Account';
insert objAccount;
}
}
Note: The 3 lines written inside of if loop won't be triggered when associated test class is running.