function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sindhura PoojalaSindhura Poojala 

Can someone guide me on how Test.isRunningTest() is used in trigger, and when does this return true and when does this return false.

Ryan GardnerRyan Gardner
Salesforce requires 75% code coverage across all your code. When you make a test class, it will be annotated with "@Test" to let the system know not to commit any insert/update/delete functions to the database. If your trigger is being called by a test class annotated with "@Test" then Test.isRunningTest() will return true. 

The reason I've seen this in some triggers is because sometimes you don't want to run certain pieces of code when it's coming from a test. i.e. Testing web services and callouts can be hard, so sometimes people just wrap it in an IF() statement to not send the callout of this is coming from a test.