function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Can I reference an extension controller variable from a trigger?

Hello all,


I have a VF page that has a checkbox "send Notification Email" that should send an email when the owner of the record changes. The VF uses an extension controller of the account where I have a EmailChecked property that receives the checkbox state in a action method from the save button on the VF page.


Now, have certain actions I want to take when the record changes, such as send the notification email. I want to know how, or if, I can read the EmailChecked property of the extension controller from the trigger to validate whether or not to send the email..


(How ) Can this be done?





Wouldn't it be better to send the email from the controller rather than delegating it to the trigger?  


You might be able to do something around this with static variables, but what happens if your trigger is invoked due to another action - programmatic update elsewhere, for example?  


Well I need the trigger to update a "custom" acount owner field, and also need to add this to the activities related list. THe reason I was going to use the trigger to send the email is since I need to retrieve several data items such as:


the new account owner(who it is changing to)

the old account owner

who is making the change


and this is readily available from the trigger. But how would I do this if I wanted to from the class?




You would clone the object in your controller so that you had the original details, then when save was clicked you would carry out the comparison.  You can find the logged in user via the UserInfo class.


If there's information in the controller that is vital to send the email, it may make sense to add that to your sobject so that its available to the trigger.