Activity Forums Salesforce® Discussions Why do we use (!Test.isRunningTest()) in Salesforce Apex?

  • Prachi

    Member
    August 29, 2018 at 12:30 PM

    Hello Anurag,

    The Test.isRunningTest() 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.

    ! is the Logical complement operator. Inverts the value of a Boolean, so that true becomes false, and false becomes true.

    So,  (!test.isRunningTest()) will Return false if the code being executed is invoked from a test class otherwise returns a true.

    Thanks.

Log In to reply.

Popular Salesforce Blogs

Enhancing Business Efficiency: Professional Salesforce Integration Services

Blog in

Salesforce integration services aim to enable seamless connections between Salesforce solutions and your other business-critical systems. In today's fast-paced digital landscape, businesses strive to optimize their operations, maximize productivity,…

Popular Salesforce Videos