+ Start a Discussion
philbophilbo 

Apex Sharing - Best Practices for Adding Manual Shares

Hi all,

 

We have some infrastructure built out that adds/removes Manual Shares on particular SObject records based on certain conditions within our application.

 

As a matter of course, situations arise where we are about to add a Manual Share to a record, but the User in question already owns the record so there's an Owner Share already in the system.  In that case, according to the Force.com documentation, we should expect the Manual Share insertion to throw a 'FIELD_FILTER_VALIDATION_EXCEPTION' exception, with error message containing the string 'AccessLevel', and best practice is to simply ignore the exception.

 

HOWEVER, we don't see this exception when we "try" to overwrite an Owner Share with a Manual Share.  Instead, we see:  'INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY' with msg 'Insufficient access rights on cross-reference id: []'.  (Note the useless nothing inside those square brackets.)  This seems to be regardless of who the owner is.  Even if the record (and Owner Share) is owned by the logged-in User, and that same User is trying to insert a Manual Share hooked to himself, the same exception is thrown.  (This user is a System Administrator, btw)

 

So what are we supposed to do?  Ignore THIS error as a matter of course?  I don't want to just start blindly doing that, in case there are situations where this does mean something really erroneous.

 

Words of wisdom anybody?  (esp. within SFDC's walls)

 

thanks