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
Nitin Palmure 5Nitin Palmure 5 

Send mass email using before delete trigger

I am trying to write a trigger which will send an email to fixed number of folks (Let's say 3). I was able to write a trigger for single user. However, I find it tricky to get it for three users. and would like to have some help.
Following is my code:
trigger triggerAlertonDeleteMarketplaceRule on Marketplace_Rule__c (before delete) {
	Messaging.reserveSingleEmailCapacity(trigger.size);
    List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();
    Set<Id> accountIds = new Set<Id>();
    EmailTemplate Et = [SELECT Id from EmailTemplate where Name =: 'Marketplace Rule Deleted'];
    for(Marketplace_Rule__c acc : Trigger.old){
        if(acc.Related_Account__c != null){
            accountIds.add(acc.Related_Account__c);
        }
        }
     Map<Id, Account> accounts = new Map<Id, Account>([SELECT Id, Name FROM Account WHERE Id in :accountIds]);
        
   
    Contact tempContact = [SELECT Id FROM Contact WHERE email =: 'nitin.palmure@abc.com'];
  	
    for(Marketplace_Rule__c mpr : Trigger.old){
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
        email.setTargetObjectId(tempContact.Id);
        email.setWhatId(mpr.id);
        email.setSaveAsActivity(false);
        email.setTemplateId(Et.Id);
        emails.add(email);
    }
    Messaging.sendEmail(emails);
  }

Please help me as there are three specific users lets take an example of three contacts with email Id as abc@123.com, def@123.com and ghi@123.com.
Thank you 
 
GauravGargGauravGarg
Hi Reddy,

Please add two more fields in email definition:
email.setToAddresses(new List<String> {abc@abc.com, def@def.com, 123@123.com});
email.setTreatTargetObjectAsRecipient(false)

Hope this helps!!!

Thanks,
Gaurav
Skype: Gaurav62990