3

From Apex trigger the batch class is executed which has With Sharing keyword. And inside the Batch class, there is a record delete statement without a CRUD check. Currently, a user who doesn't have delete access and if this batch is executed by this user via trigger, then without any error records get deleted.

enter image description here

In this case, With Sharing keyword in batch apex is not enforced CURD access check. Does it mean, this batch class runs in System mode, if we don't add additional CRUD and FLS check using "isDeletable" method?

1 Answer 1

4

The with sharing keyword enforces record-level access (sharing). It does not enforce CRUD or FLS against your code. If you wish to do so, you still have to write manual checks for CRUD and FLS.

2
  • or put another way , the running user will never even see a record in the batchable's start() that they don't have sharing access to
    – cropredy
    Jun 23, 2021 at 18:05
  • or just call out as all apex runs in system mode all the time ie not respecting CRUD or FLS unless explicitly specified except apex in standard controllers or anonymous window. Amazing thing is even runAs method in test classes doesnt respect CRUD or FLS.
    – Elijah
    Jun 25, 2021 at 1:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .