Play Games

Search This Blog

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.

No comments:

Post a Comment