2

We also have an issue where Salesforce Support hasn't been a lot of help. We have some Apex code that was developed by a Salesforce contractor. We have a custom object and we have Apex code making a Manual Sharing rule for that object to a Community Power user. We have noticed that (without the OwnerId changing on the custom object mind you), the sharing rules are no longer there. I have been told that if the OwnerId changes on a record, all manual sharing rules are removed. I am hoping someone here can tell me if that is true or not.

The Apex code is making a manual sharing rule.

Custom_Obj__Share platSharingRule = new Custom_Obj__Share();
platSharingRule.ParentId = cont.Id;
platSharingRule.UserOrGroupId = usr.Id;
platSharingRule.AccessLevel = 'Read';
platSharingRule.RowCause = Schema.Custom_Obj__Share.RowCause.Manual;

My question is should we be using Manual sharing for the Row Cause? Should this be using an Apex sharing rule?

  • 1
    It is true that manual shares are removed if the owner is changed. Do you have any field history tracking? Maybe that can help you see if the owner is being changed for some reason and then changed back to the original owner. – adriancg Jul 30 at 20:03
3

From the Manual Sharing section of the document "A Guide to Sharing Architecture" https://developer.salesforce.com/docs/atlas.en-us.dat.meta/dat/dat_components.htm

Manual sharing is removed when the record owner changes or when the sharing access granted doesn't grant additional access beyond the object's organization-wide sharing default access level. This also applies to manual shares created programmatically.

Only manual share records can be created on standard objects. Manual share records are defined as share records with the row cause set to manual share

Apex Sharing Reasons

I would recommend looking into using custom share reasons rather than using the Manual type for your custom objects shares. These custom shares are not wiped out like the Manual ones upon record sharing recalculation.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_bulk_sharing_creating_with_apex.htm

| improve this answer | |
  • This is what I was fearing. We had a salesforce partner/contractor that built this code and didn't explain what or why. I'll see if we can update the code and let you know how it goes – Mayday Jul 31 at 15:22
  • We finally heard back from Salesforce Support and they confirmed that any sharing rule marked as Manual can be purged automatically by backend processes. I would suggest anyone using Apex to make sharing rules knows this fact and that they should be using an Apex sharing cause. – Mayday Jul 31 at 17:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.