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

Popular Salesforce Videos