function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
grajangrajan 

Apex Managed Sharing Not Committed.

Hi,

I have a sharing trigger on contact object. While inserting the contact my trigger (After insert trigger) will sharing that contact with particuler user. Also I have a workflow field update to assign the owner of the contact based on the state.

Problem:
Case 1: If my inserted contact meet the workflow cretiria then my shared contact will not committing. (Without any error)

Case 2: If my inserted contact not meeting the workflow cretiria then my shared contact will get committed.

Question: Why the shared contact not committed while owner changed by workflow?
bob_buzzardbob_buzzard
I suspect this is because of the change of ownership. According to the docs at:

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_bulk_sharing_creating_with_apex.htm

It is possible to manually share a record to a user or a group using Apex or the SOAP API. If the owner of the record changes, the sharing is automatically deleted.

Thus if your sharing rowCause is 'manual' (or undefined, as this is the default), then changing the owner will discard the sharing.