My_Test_Repo/force-app/main/default/classes/JourneyHandler.cls

35 lines
1.4 KiB
OpenEdge ABL

public class JourneyHandler {
public static void journeyHandlerMethod(Map<Id, Player__c> oldPlayers, Map<Id, Player__c> newPlayers){
List<Messaging.SingleEmailMessage> mailList = new List<Messaging.SingleEmailMessage>();
for(Player__c play : newPlayers.values()) {
Player__c oldplay = oldPlayers.get(play.Id);
// Check if 'Country__c' field is updated
if(oldplay.Country__c != play.Country__c) {
// Create a new email
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
// Set the recipient email address
mail.setToAddresses(new String[] {play.Email__c});
// Set the email subject
mail.setSubject('Country Change Notification');
// mail.setTemplateId(emailTemplate.Id);
// Set the email body
mail.setPlainTextBody('Dear ' + play.Name + ',\n\nYour country has been updated from ' + oldplay.Country__c + ' to ' + play.Country__c + '.\n\nBest,\nYour Team');
// Add the email to the list
mailList.add(mail);
}
}
// Send all emails in the list
if(!mailList.isEmpty()) {
System.debug('Mail sent ');
Messaging.sendEmail(mailList);
}
}
}