+ Start a Discussion
Dippan PatelDippan Patel 

Can triggers execute if user doesn't have access to it?

Hi, 

If I install a managed package for admin and the package has triggers on after-insert  after-update and other classes. Now if a record is created by a user who do not have access to that trigger and classes, will it execute after insert and after update trigger?

Thanks!
Best Answer chosen by Dippan Patel
SwethaSwetha (Salesforce Developers) 
HI Dippan,

If the trigger is active,  after insert and after update events are fired. The important consideration here would be if code is running with or without sharing permissions.

The context of the user executing the Apex code is important. By default, Apex executes in system context. Apex code has access to all objects and fields. Object permissions, field-level security, and sharing rules aren’t applied for the current user. You can use the with sharing keyword to specify that the sharing rules for the current user be taken into account for a class. Check out Using the with sharing or without sharing keywords.(https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_keywords_sharing.htm)
 
Hope this helps you. Please mark this answer as best so that others facing the
same issue will find this information useful.
 
Thank you

All Answers

AnudeepAnudeep (Salesforce Developers) 
Hi Dippan, 

My understanding is as long as the trigger is active, an after insert and after update will invoke it regardless of the choice 'Install for Admins Only' or 'Install for All Users' and who has created it

There are certainly differences interms of access for both the options 'Install for Admins Only' and 'Install for All Users' which is outlined below

https://help.salesforce.com/articleView?id=distribution_installing_packages.htm&type=5 (https://help.salesforce.com/articleView?id=distribution_installing_packages.htm&type=5)

Guess you can verify this behavior by installing a package in the org
(Including installation link below for FSL package that has bunch of triggers to test this bheavior)

https://help.salesforce.com/articleView?id=pfs_install.htm&type=5 (https://help.salesforce.com/articleView?id=pfs_install.htm&type=5)

Anudeep
SwethaSwetha (Salesforce Developers) 
HI Dippan,

If the trigger is active,  after insert and after update events are fired. The important consideration here would be if code is running with or without sharing permissions.

The context of the user executing the Apex code is important. By default, Apex executes in system context. Apex code has access to all objects and fields. Object permissions, field-level security, and sharing rules aren’t applied for the current user. You can use the with sharing keyword to specify that the sharing rules for the current user be taken into account for a class. Check out Using the with sharing or without sharing keywords.(https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_keywords_sharing.htm)
 
Hope this helps you. Please mark this answer as best so that others facing the
same issue will find this information useful.
 
Thank you
This was selected as the best answer