0

Context

  1. Account read privilege is at user level
  2. Sharing rule allows Users to see other User's Account records, Read privilege only.
  3. An LWc on a Visualforce Page allows a user to perform some business process on any account.
  4. The above causes a new record to be created in AccountContactRelation(ACR) object.

Issue/Error (see title) at step 4

  1. This is because the User is not having "write" privilege on other User's Account record. Only read via sharing rules.

Options tried but didn't work

  1. Apex job: same issue: I thought it will run under system/admin mode but the same error says that its running under user mode. Why ?
  2. Without Sharing explicitly mentioned on the apex control class that handles the ACR record creation. Runs in User Mode.
  3. Writing code under trigger also fails. And trigger runs under system mode.
  4. Cannot set object level permission on ACR OBJECT in permission set.

Query

  1. Will Modify All on Account work ?
  2. How to run in system mode either sync or async ?
  3. How to check runtime if my apex code is running under user or system mode.
8
  • Check the "must have" settings on the master details field that references the account or contact in the junction object. May say you must have write.
    – Phil W
    Commented Mar 4, 2022 at 18:31
  • Hi Phill, I have checked and re-checked the "must haves" settings and I concur with your last sentence, since it works as soon as I provide a Write privilege, which Business don't want to opt for now. Any suggestions on why code is not running in system mode in Apex Job and/or any possibilities of running a code under "system" ? Commented Mar 5, 2022 at 1:50
  • System mode is about permissions, where as sharing is controlled by the Apex class's "with", "without" or "inherit" sharing. Maybe change the class creating the junction object to "without sharing"?
    – Phil W
    Commented Mar 5, 2022 at 5:08
  • Hi Phil, I had tried and even retired (another simple straightforward flow) your suggestion as well but no luck. I even tried writing directly inside a Trigger (which as per Salesforce runs under "system") In short, system mode is just about ability to "read" "all" records/setting/etc across the platform/org. It does NOT mean that you can create/update/delete records, Salesforce does enforces the security privilege of the current User's context when performing these operations (create/update/delete). Commented Mar 6, 2022 at 8:03
  • System mode is not the same as sharing. Screen flows allow both aspects to be controlled, for sure, and Apex classes permit sharing to be turned off. In triggers, look at Sharing Considerations in this documentation.
    – Phil W
    Commented Mar 6, 2022 at 8:09

0

You must log in to answer this question.

Browse other questions tagged .