Custom Object - OWD (public read only) Apex(no sharing specified) and the apex is the entry point Object level permission on profile is read

I was trying to update a custom object logging in as a user with custom profile that does has view/View all object permission.

I have a custom lightning component that calls an apex method. The apex method tries to update the custom object and i get the below error.

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

According to Salesforce documentation, Apex should be ignoring object level permission and be able to update the record.

I need to understand why this behaviour happens?

Custom object has OWD settings as "Public Read only" and there is no sharing rule.

The issue resolves if I add "Modify All" permission in the profile in the object level or if I change the OWD to public read write.

But in the apex class I did not specify sharing (which means it should behave as without sharing) and that is the entry point of the lightning component

  • Is your class with or without sharing?
    – kurunve
    Jul 10, 2019 at 18:39
  • In the apex class I did not specify Sharing (which means it should behave as without sharing) and that is the entry point of the lightning component. I have updated my description with more details Jul 10, 2019 at 19:17
  • @RajaVivekanandhan Actually that is incorrect. If you don't specify with or without sharing, then the Apex class inherits from whatever class calls it. If it's at the top most level of the call stack, then it defaults to using sharing rules. developer.salesforce.com/docs/atlas.en-us.apexcode.meta/… Jul 10, 2019 at 19:42
  • @JamesLoghry in the link you sent me it says " If the class is used as the entry point to an Apex transaction, an omitted sharing declaration runs as without sharing. " . This apex class is the entry point (top most level in call stack directly called from lightning controller) and no other apex class is calling this apex method. Jul 10, 2019 at 19:53


You must log in to answer this question.

Browse other questions tagged .