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
Tulasiram ChippalaTulasiram Chippala 

How to exceed email limit

We have a requirement for uploading lead. After inserting leads either through import wizard or dataloader, owner should be notified.

But the issue is sending too many emails to single users if he owned too many records.

How we can send single email for owner who owned too many records.

Ex: 20 owners for 200 records. Suppose first user has 10 records, then send single email to that owner instead of sending 10 emails to the same user(that mail has to include all 10 records info like Name, Company, id etc....).

We tried using for loop to create a mail body for all those 10 rcords for single owner. 

In this scenario there are 20 owners so my code is creating 20 mail bodies. Then it is creating 20 single email message methods. Exceeding limit.
Is there any option to avoid this limit??

Pls suggest me a solution...

Thank you!
Raj VakatiRaj Vakati
In that case you need to send the email using apex trigger .. 
In apex, trigger you can able to do like this 

trigger postallead on Lead (after insert) {
	Map<String,String> valuesMap = new Map<String,String>();
   for (Lead myLead : {
	   valuesMap.add(myLead.OwnerId ,myLead.Owner.EMail) ; 
    List<Messaging.SingleEmailMessage> mails =  new List<Messaging.SingleEmailMessage>();
          Messaging.SingleEmailMessage mail =  new Messaging.SingleEmailMessage();
          List<String> sendTo = new List<String>();
          // Set email is sent from
          mail.setSenderDisplayName('Email Notification');
          // Set email contents
          mail.setSubject('New Lead');
          String body = 'Dear , ';
          body += 'New Lead is inserted .' ;
  // Send all emails in the master list
  if(mails.size()>0)    Messaging.sendEmail(mails);