My managed package contains a trigger for Cases. When users have no license an Apex batch class called from that trigger fails with
First error: Insufficient user privileges
My initial assumption was that packaged code is not called by unlicences users but then I found this thread where it says:
Triggers run in system mode. All the time. Just because the user isn't licensed doesn't mean the trigger itself won't run.
UserInfo.isCurrentUserLicensedForPackage() to write logic to prevent such errors.
I now have 2 questions:
- Is it failing because a Batch job is NOT running in System mode as triggers?
- What is the recommended way (documented where?) to prevent such errors in packaged code using
UserInfo.isCurrentUserLicensedForPackage()? Are there libraries or patterns to not have this check in every class or my app?