You need to sign in to do that
Don't have an account?
Rajasekhar RS
Need apex or trigger
Hi everyone
whenever any new offer is created into system for any product. Send
Email alert to all customers with the offer and product details
whenever any new offer is created into system for any product. Send
Email alert to all customers with the offer and product details
// Get all customers
List<Customer__c> customers = [SELECT Email__c FROM Customer__c];
// Get the new offer
Offer__c newOffer = Trigger.new[0];
// Get the related product
Product__c product = [SELECT Name FROM Product__c WHERE Id = :newOffer.Product__c];
// Create a list to store the emails
List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();
// Loop through the customers to send an email to each one
for (Customer__c customer : customers) {
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
email.setToAddresses(new String[] { customer.Email__c });
email.setSubject('New Offer for ' + product.Name);
email.setPlainTextBody('A new offer is available for ' + product.Name + ': ' + newOffer.Name + '\n' + newOffer.Description__c + '\n' + 'Discount: ' + newOffer.Discount__c + '%');
emails.add(email);
}
// Send the emails
Messaging.sendEmail(emails);
}