+ Start a Discussion
Lee SinLee Sin 

Criteria based sharing rule

I want to programmatically change the Criteria based sharing rule on Account.

After read the material, I found nothing.

I want to change the criteria through apex or enable/disable a sharing rule through apex.

My scenario:
I want to open certain accounts to users for them to work on. When a goal is reached, the manager can click a button to hide the accounts from the users. And when the next month comes, the manager clicks a button to enable the sharing rule.

You will have to manipulate Share objects inorder to programatically manage Record Sharing.You can also check https://developer.salesforce.com/page/Using_Apex_Managed_Sharing_to_Create_Custom_Record_Sharing_Logic for more information
PratikPratik (Salesforce Developers) 
Hi Lee,

You can create sharinf through Apex sharing all together rather than modifying the existing rule. You can delete the existing rule and create apex sharing to share the records as per the criteria.

You can refer to:

for sharing accounts: