function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rajasekhar RSRajasekhar 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
Shri RajShri Raj
trigger NewOfferTrigger on Offer__c (after insert) {
    // 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);
}