System mode or God mode in Apex – Gotchas

Gotchas of System mode or God mode in Apex and its impact by using “With sharing” keyword in Salesforce

In many of my previous implementations I have used advantage of Apex code running in System mode however never tried how far it can go in terms of capabilties. There is no specific Salesforce documentation which can explain that what is allowed or not allowed in System mode.

In this post, we will go through some scenario and will try to understand what really is possible in Apex System mode and when it can fail.

Before diving more lets discuss how many types of mode do we have in Apex ?

User Mode : As per this Salesforce post, all Profile level permissions, sharing rules and Field level security are enforced in Apex if it runs in User mode. Standard Controller and Anonymous Apex runs in User mode.

System Mode : Same post conforms that custom controller, trigger, Apex class, controller extension works in System mode. Means eventhough user does not have necessary profile level permission, record level permission or field level permission, but still they can perform any operation on it.

Continue reading “System mode or God mode in Apex – Gotchas”