function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Adarsh Bhat GAdarsh Bhat G 

Criteria based sharing rule not applicable in Test Class

Hi,
I have an issue with test classes due the sharing rules. The account OWD setting is set to private. And there is criteria based sharing rule which shares account to all internal users.

In the test method, when we use System.runas(Internal User), the record is invisible even though the account should have been shared with all internal users by sharing rules. 

There is an open idea for the similar issue :
https://trailblazer.salesforce.com/ideaView?id=0873A0000003eEWQAY

How can we make sure criteria based sharing rules is visible in Test classes?

Thanks,
Adarsh
mukesh guptamukesh gupta
Hi Adarsh,

Criteria Based Sharing rules aren't evaluated during Apex test classes

https://help.salesforce.com/HTViewHelpDoc?id=security_sharing_cbs_about.htm&language=en_US (https://help.salesforce.com/HTViewHelpDoc?id=security_sharing_cbs_about.htm&language=en_US)

The documentation states that "Criteria Based Sharing Rules cannot be tested" which I assume this refers to this.

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh 

 
Adarsh Bhat GAdarsh Bhat G
Thank you for your response.  If it is not possible to validate, then any idea on how to fix this issue? How can we make  an account visible to the internal user when we use System.runas()?
 
Thanks,
Adarsh