Activity Forums Salesforce® Discussions What does Test.isRunningTest() identifies in the Apex class in Salesforce? Reply To: What does Test.isRunningTest() identifies in the Apex class in Salesforce?

  • Shweta

    Member
    September 4, 2020 at 2:38 pm

    Test.isRunningTest(): This method is used to identify if the piece of code being executed is invoked from a Test class execution or from other artefacts such as a Trigger, Batch Job etc. Returns true if the code being executed is invoked from a test class otherwise returns a false.
    This method usually comes in handy, when you intend to conditionally restrict execution of certain Apex code blocks, based on whether they are being invoked from a test class or not.