We update some objects in our trigger handler, the user does not have access to these objects.

We want the trigger handler to run in System mode. Should we have the 'without sharing' keyword on the handler class.

Also is this is updateable in the managed package if we had the class declared as 'with sharing' before.

2 Answers 2


The "with/without sharing" setting only controls access to records; not objects or fields. That's not a problem here though, since all classes, triggers, controllers, and controller extensions run in system mode by default. (Only anonymous apex runs in user mode.)

Unless you're the package creator, you can't update code in a managed package.

I hope this helps!


Hmmm, it matters. With Sharing controls access to records, regardless of whether Apex runs in system context or not.

In Trigger context, chances are you'd want to execute the logic for ALL records (without sharing or just leaving the sharing keyword out), not just the records the user has access to (with sharing).

The best way to check is to test it out yourself, using a handler class and changing the with sharing/without sharing keyword. Notice the difference in behaviour when testing it out for a user that does not have access to all records.

  • 2
    Default behavior is not without sharing, but rather inherit sharing. They actually added a keyword specifically for this in W19, so there is no longer any reason to ever omit sharing specification in your class declaration.
    – Adrian Larson
    Commented Jan 8, 2019 at 4:31
  • 1
    Hi @AdrianLarson, I agree in relation to inherit sharing. The point I was trying to get at is to be mindful when using with sharing for Trigger handler classes. Commented May 9, 2019 at 4:12
  • @AdrianLarson, default behaviour of what? Do you mean the default used when writing the handler should be "inherited"? Then the actual question is, what sharing declaration is passed by the trigger? Bc only if the trigger runs "without" the handler will, too. Otherwise default for "inherited sharing" is "with sharing".
    – Schnaps
    Commented Jan 31, 2020 at 7:47

You must log in to answer this question.

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