+ Start a Discussion

How to run trigger in user context to pass App Exchange security review?

Hi All,
Recently, We have been asked to make trigger to run in user context. Please help me if any body has gone thru this kind of secuirty check for trigger. Thanks in advance.

Pawan Kumar
SandhyaSandhya (Salesforce Developers) 

All triggers run as System by default. This means that triggers may have access to objects and fields that the current user does not. You can override this using the "with sharing" keywords.

Please refer below links with the similar discussion to get more information.



Hope this helps you!

Please mark it as Best Answer if my reply was helpful. It will make it available for other as the proper solution.
Thanks and Regards

Thanks sandhya.

Certainly, shared links are useful.

I have below trigger and their corresponding Trigger Handler class. My queston is optyList(Trigger.New) will have all the record which may not be accessible to running user. How to take out such record(unaccessible record) from the optyList. Please correct me if i am doing anything wrong / my undertanding is wrong as far as passing Trigger.New as parameter to trigger handler class.

trigger updateOpportunityTrigger on Opportunity  (after insert) {
    // In the above line, Trigger.New will not respect with sharing 

Trigger Handler
public with sharing class  SystemMode_Scenario {
    public static void perform(Opportunity[] optyList){
        // feedItemsList will contains some record 
        // which will not be accessible to running user,how to remove such record from optyList.

        for(Opportunity eachOpty : optyList){
            eachOpty.SomeCustomField__c = 'Updated' ;
            update eachOpty;

Pawan Kumar
Pratap Garani 9Pratap Garani 9
Hey Pawan,
If u are using with Sharing the first thing which will be checked is object acess, next the field access and then the sharing access. If a record is shared with you or u r the owner of that that ur code will update that record only.
Pankaj Singh 233Pankaj Singh 233
Hey Pratap with sharing only checks user sharing rules. Nothing else as per the doc : https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_keywords_sharing.htm