• Karishma K 2
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hi all,

I am trying to send an email using single email message and I am unable to overcome the SINGLE_EMAIL_LIMIT_EXCEEDED exception.  I am using html email template and I am using the mail.setTargetObjectId(con.Id) as contact Id. When I am sending an email to contact, is it still considered as external email?

By the search I cam to know that email to User, Contact and Lead is considered as salesforce internal emails and linitation will not applicable for this. Please correct me if this is wrong.

I think this exception will not come, if the email is considered as salesforce internal email?

Please help me to overcome this exception. Below is the code I have used.

public PageReference sendEmail() {
    Customer__c customer;
    customer = [ SELECT Id, Email__c, Name, Salesforce_Org_Id__c FROM Customer__c WHERE Id =: 'a009000000q4Rek'];
    contact con = new contact();
    con.email = 'manu.tej@ceptes.com';
    con.LastName = 'Manu';
    insert con;
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            EmailTemplate et =[SELECT Id, HtmlValue, DeveloperName FROM EmailTemplate WHERE DeveloperName = 'Order_Delivery_Email' ];
            String subject = 'Order Reference Number : ORD - 010' ;
            String emailBody = ((String)et.HtmlValue).replace('**Customer Name**',customerName ).replace('**Order Reference Number**',customerName );
            String [] toAddresses = new String [] {emailAddress};
            mail.setTargetObjectId(con.Id);
            mail.setSubject(subject);
            mail.setSaveAsActivity(false);
            mail.setHtmlBody(emailBody);
            mail.setSenderDisplayName('Support');
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
    return null;
    }

Thanks in advance.

R - Manu