Activity › Forums › Salesforce® Discussions › Can we delete records in share table with row cause as Rule?
Tagged: Delete, Rule, Salesforce Apex, Salesforce Records, Sharing Rule
-
Can we delete records in share table with row cause as Rule?
Posted by Himanshu on April 30, 2016 at 6:29 PMCan we delete records in share table with row cause as Rule?
Matheus replied 9 years, 5 months ago 3 Members · 2 Replies -
2 Replies
-
As per the http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_bulk_sharing_understanding.htm
it is not possible. “All implicit sharing added by Force.com managed sharing cannot be altered directly using the Salesforce user interface, SOAP API, or Apex”
Howsoever, the work-around is this:
You need to change the Sharing Rule which is causing the share. which is to delete a record with Sharing type Rule
If(Trigger.IsUpdate){ List<OpportunityShare > sharesToDelete = [Select o.UserOrGroupId, o.RowCause, o.OpportunityId, o.OpportunityAccessLevel, o.Id From OpportunityShare where RowCause=:Schema.RowCause.Your_Sharing_Rule__Here and o.OpportunityId='######']; }
And then do this:
if (!sharesToDelete.isEmpty()) {
delete sharesToDelete;
} - [adinserter block='9']
-
Salesforce.stackexchange.com is your friend ☺️
Not possible, according to the documentation: “All implicit sharing added by Force.com managed sharing cannot be altered directly using the Salesforce user interface, SOAP API, or Apex”
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_bulk_sharing_understanding.htm
In order to get rid of this, you need to change the Sharing Rule causing the share.
Log In to reply.