0

Is it possible to write a trigger that will update a field value for a user even though the user doesn't have edit access to that field?

In my example, I have a contact page layout with a custom button attached to a trigger. The trigger does three things:

  1. Gathers the contact record id.
  2. It displays a VF page and gets the user to tick a box.
  3. It updates the "Ticked_the_box__c" check box field to TRUE for the contact id.

I want to know if I can get the code to execute successfully even though the user's profile doesn't have edit access to the field.

4

Since a trigger runs in system context, yes it should update the record even though the user's profile doesn't have edit access to the field.

1

Apex always runs in system context, not taking into account sharing rules, validation and field level security, etc. So yes, the trigger will be able to update the field that is read only for the user.

See for more information about the permissions enforcing such as field level security http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_perms_enforcing.htm or https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_keywords_sharing.htm if you want the trigger to respect the sharing rules and field level security of the user, instead of running in system mode.

0

you can use the runAs method as the user you want to test your trigger..

https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_testing_tools_runas.htm

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.