3

I have a field that is used in an email template for which no FLS is granted in any profiles.

The Apex code that sends the email using messaging.sendEmail() is invoked from a trigger so I assume it to be running in system mode and that FLS is not relevant.

However, when that email is sent, and the trigger is executed by a record update, made when logged into a community as a user with profile BoringUser, the referenced field is not rendered into the email.

If I add read permissions for the System Administrator profile and perform the same operations. Log into community as BoringUser, cause a record update. Trigger fires and sends email, then the email received contains the expected merge field.

Why does granting read permission to the System Administrator profile influence field level access for code that should be running in System Mode?

  • 2
    one has to be a bit careful sometimes when logging into a community when already logged in as an employee. Can you verify the above when logging into the community in an incognito window as a BoringUser – cropredy Jan 24 at 19:58
  • @cropredy Thanks for the idea, unfortunately I have been testing this with a real login from an incognito window. No 'login as' involved. – RobD Jan 24 at 23:16
  • 1
    Is there a controller extension involved that makes the update to the record from the community that enters the trigger? – Kris Goncalves Jan 27 at 23:32
0

In order to make trigger run in System Mode you have to mark the class as without sharing (public without sharing class MyClass). This would give BoringUser access to the fields he shouldn't have only to send the email.

| improve this answer | |
  • Thanks for the suggestion @Attilio Capocchiani as it happens the code concerned is annotated with withoutSharing already. I don't think that this is a factor though, sharing shouldn't affect FLS, only record visibility. – RobD Jan 27 at 10:08

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.