I have a custom object myObj. I am trying to write a trigger when the record is shared for this object with any user. Salesforce creates myObj__Share object for sharing. I can see when I share a record to any user, myObj__Share is updated with a new row for access level for the user. I like to execute a trigger or capture the post save event when any record is share for myObj with any user. Is there anyway to execute or write an apex after a record is shared for any customer object
1 Answer
You cannot write trigger on the share objects. This is not allowed as now.
There are 2 solution that I think you can implement:
1)Custom Button: Replace the standard share button from the page layout with a custom button. Use this button to add / remove shares, you can insert share records from APEX. And when a new record is inserted, you run your code. But sharing may happen from other parts of code, so this solution is not 100% accurate.
2)Schedule Class Run a schedule job in very small intervals, check if there are new share records inserted into the system and then run your code. This is 100% guaranteed to cover all the records but this will not be real-time. So in case you want some immediate action like updating a field then it may become an issue.