+ 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.
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_bulk_sharing_creating_with_apex.htm

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.


 
Suneel#8Suneel#8
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:
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_bulk_sharing_creating_with_apex.htm

for sharing accounts:
https://www.salesforce.com/developer/docs/api/Content/sforce_api_objects_accountshare.htm

Thanks,
Pratik