We can send emails programmatically in Apex, however if we're not
careful we can hit the measly governor limit of 10 in no time at all. We know, although outbound email limit is 1000 with Apex, but only a
total of 10 sendEmail method calls are allowed in each context.
Obviously the way to avoid this is to gather up all emails we want to send in a list and call the sendEmail method once from your Apex context. When passing an argument to the sendEmail method it must be of type Email.
In the mean while we need to check how many times we have already called send email method in a transaction and how more are remaining.How will we do that?
Below is the few lines of code.
Integer used = Limits.getEmailInvocations();
Integer emailLimit = Limits.getLimitEmailInvocations();
System.debug('print--used ->'+used );
System.debug('print--emailLimit ->'+emailLimit );
Obviously the way to avoid this is to gather up all emails we want to send in a list and call the sendEmail method once from your Apex context. When passing an argument to the sendEmail method it must be of type Email.
In the mean while we need to check how many times we have already called send email method in a transaction and how more are remaining.How will we do that?
Below is the few lines of code.
Integer used = Limits.getEmailInvocations();
Integer emailLimit = Limits.getLimitEmailInvocations();
System.debug('print--used ->'+used );
System.debug('print--emailLimit ->'+emailLimit );
No comments:
Post a Comment