One of the most common use cases not supported by sharing rules is when we have a lookup field to the user object and whomever is selected in the lookup field will automatically get read/write access to the record.
Can we design a reusable code/trigger to do this? Its one of the most common things that we had to create a trigger for.
More information on creating a trigger: http://wiki.developerforce.com/page/Using_Apex_Managed_Sharing_to_Create_Custom_Record_Sharing_Logic
I've had some success using the following code:
LeadShare leadShare = new LeadShare(); leadShare.ParentId = '00QC00000121LCI'; leadShare.UserOrGroupId = '005C0000003N5lT'; leadShare.AccessLevel = 'edit'; insert leadShare;
Here are some of my considerations: - How can we get the different rowCause from Apex? - How can we determine if the OBJECTNAME__Share is available?
Feel free to share other information that need to be considered. Thanks!