
Force.com Cookbook Sample Code
Chapter 8: Customizing Salesforce Pages and Fields - Allowing Users to Subscribe to Record Update Notifications
To download all the code samples, access the Cookbook. -
This Apex trigger is part of a solution involving custom objects, email templates, and workflow rules, that lets users subscribe to email alerts every time a record is updated.
trigger Email_Account_Subscribers on Account (after update) {
for (Account_Subscriber__c[] subs : [select Id, Last_Email_Sent__c from Account_Subscriber__c
where account__c in :Trigger.new]) {
for (Account_Subscriber__c sub : subs) {
sub.Last_Email_Sent__c = System.now();
}
update subs;
}
}
Sample code provided by salesforce.com. All rights reserved.