I would like to distingish sharing between manual sharing and apex sharing

For example please check below code:

Code snippet

List<Document__Share> lstDocSharesDelete1 = [select Id,UserOrGroupId,RowCause from Document__Share where ParentId in:docId and (RowCause!='Owner')];
        for(Document__Share dc:lstDocSharesDelete1){
            if(String.valueOf(dc.UserOrGroupId.getSObjectType())=='Group' && dc.RowCause=='Manual'){

Here I'am checking dc.RowCause=='Manual'in code level,If I do share the record manually also it becomes true.

So How Can I distinguish it?

  • For custom objects you can define a rowcause for apex sharing. For standard object you are SOL
    – Eric
    May 24 '18 at 7:28
  • Give this a try: dc.RowCause== Schema.Document__Share.RowCause.Manual
    – Mr.Frodo
    May 24 '18 at 7:30

Unfortunately, Custom Sharing Reasons are only available for custom objects. For standard objects, the only Row Cause you can use is Manual in Apex, so there is no way to see the difference between 'user manual' sharing and apex sharing the standard Document object you are using.

See the documentation:

Apex sharing reasons and Apex managed sharing recalculation are only available for custom objects.


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.