Activity Forums Salesforce® Discussions What is the purpose of @testVisible annotation in test class in Salesforce?

  • What is the purpose of @testVisible annotation in test class in Salesforce?

    Posted by Anuj on April 6, 2020 at 2:29 pm

    What is the purpose of @testVisible annotation in test class in Salesforce?

    Shubham replied 4 years, 8 months ago 3 Members · 2 Replies
  • 2 Replies
  • Udit

    Member
    April 6, 2020 at 2:41 pm

    Hello Anuj,
    If you have an Apex class or controller, It has a Private or Protected variable or methods or inner classes, so you can't access them in other classes. But using this @testVisible annotation in a Private or Protected variable or methods or inner classes safely expose them only for test classes.

  • Shubham

    Member
    April 6, 2020 at 2:52 pm

    Hi Anuj,
    TestVisible annotation allows test methods to access private or protected members of another class outside the test class. These members include methods, member variables, and innerclasses. This annotation enables a more permissive access level for running tests only. This annotation doesn’t change the visibility of members if accessed by non-test classes.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos