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

Apex Sharing Problem - Please Help!

Hello All,


Following is the scenario in question:


1. Account A1 and Custom Object C1 are Master-Detail relationship
2. Organization wide Default setting on A1 is Private
3. Custom Object C1 is controlled by A1
4. There was existing record R1 of type C1 that referenced A1 (relationship id). Record owner is User U1
5. User U2 was required to update record C1 including associated referenced field
6. Trigger T1 (before update) on Custom Object C1 created AccountShare A1 with EDIT privilege granted to User U2
7. User U2 updated record R1 in step 2 including associated relationship field (A1) Id
8. Received below error


Update failed. First exception on row 0 with id a1LV00000007KIaMAM; first error: INSUFFICIENT_ACCESS_OR_READONLY, insufficient access rights on object id: []"


Please note that it was not possible to share record R1 in step 4 at creation time (after insert) because at the time User U2 did not exists on the system. Therefore the trigger in Step 6 was created after the fact and designed to share record C1 with User U2 just before the latter updates the record. Though not sure if this is the correct solution since an error was encountered.


Can someone please let me know what is wrong with this solution and how to resolve the issue.


Thanks in advance,




One question.Don't get it all.

In step 4 you say that there was existing record of type C1 that referenced A1. So this must be the master-detail relationship then?

In step 5 user U2 was required to update C1 including associated referenced field. Do you mean updating the master-detail relationship? Because this is not possible. Or are you saying that they had a lookup field relationship before they became master-detail?


Another thing to check might be that the profile of user U2 has field-level access to the fields you want him to update on record C1.


BR / Niklas