2

The question is simple: should test classes be defined with sharing with sharing | without sharing | inherited sharing to pass the security review?

Technically Salesforce enforces this by saying it in their documentation:

Mark all (non-interface) classes as either with sharing, without sharing, or inherited sharing.

Yet it seems redundant for test classes. If it really needs to be, then why?

0

Test classes does not have concept of sharing because you would never use test class to get/post/delete/other DML/queries in test class/methods.

But, you would use test classes and its methods to check whether record accessibility for view/read/delete is as per business specifications in given Apex classes

| improve this answer | |
  • 3
    I don't think I agree here. Test class behavior can definitely change based on whether or not the class is declared with sharing. – David Reed Jul 23 '19 at 17:43
  • So does the security review team require test classes to be declared with sharing specification? – Eduard Jul 24 '19 at 7:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.