User Story
As a sales team member, I want to receive email notifications when the probability of closing an opportunity exceeds 50%, so that I can promptly review and update the opportunity stage as necessary.
Codes
trigger SendNotificationOnProbabilityChange on Opportunity (before update) {
for (Opportunity o : Trigger.new) {
if (o.Probability > 50 && o.Probability != Trigger.oldMap.get(o.Id).Probability) {
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(new String[] {'enginbasturk61@gmail.com'});
mail.setSubject('Probability over 50% for Opportunity ' + o.Name);
mail.setPlainTextBody('The probability for the opportunity ' + o.Name + ' has increased to over 50%. Please review the opportunity and update the stage as needed.');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
}