public class JourneyHandler { public static void journeyHandlerMethod(Map oldPlayers, Map newPlayers){ List mailList = new List(); 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); } } }