+ Start a Discussion
sravusravu 

Dynamically create sharing rules

Hi,

Is there a way to dynamically create sharing rules based on some predefined rules. like giving access to records dynamically using apex triggers/controller.

 

Thanks in advance.

Ritesh AswaneyRitesh Aswaney

Yes Apex Sharing is possible. Whenever you set the Sharing Model of an Object to not Public Read Only or greater, an Object_Share, eg. Account_Share table is created. Inserting records in this row is possible via Apex Triggers / Code and enable programmatic sharing.

 

http://wiki.developerforce.com/index.php/Using_Apex_Managed_Sharing_to_Create_Custom_Record_Sharing_Logic

 

In addition Spring 11 also introduced Criteria Based Sharing Rules, where you can via config define sharing rules based on some logical conditions.

PlaystationPlaystation

I've been trying to figure out for several days why is the MyCustomObject__Share for one of my objects not available.  Then I read here that you have to set the "organization wide default" for that object to anything other than public.  It worked :smileyvery-happy: !  Now I can try experimenting with trigger-controlled (apex managed) sharing.

 

:smileysad:

(hate being a newbie:  I know what I want, I just can't figure out how to do it SalesForce way.)