Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a requirement in which I have to write code to send mail to people who are neither contact nor lead. They are people working in our company and do not have any Salesforce login. I have created a workaround by creating contacts of them. And it is always a dangerous thing to have them in Contact as Admin can delete them by mistake. If not now sometimes in future. So my concern is to have a solution in which I can send mail to them without any fear of loosing there contact as it is a continuous basis process. This mail does not go to our client and wholly and solely for internal purpose. Can somebody help me.

share|improve this question

Salesforce provides functionality to send email to any person regardless of Contact or Lead or User. However it is bound with a quite restrictive Salesforce governor limit:

to a maximum of 1,000 external email addresses per day

Here is a sample code to send email to any email address:

    Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();                  

    String subject = 'Subject Line ';

    // text
    String body = 'Information you need to send'; 

    // Set HTML body for nice foramtting

    // Set eamil address of person who you want to send the email. Also you can set multiple email addresses too.
    email.setToAddresses(new String[]{''});

    Messaging.sendEmail(new Messaging.singleEmailMessage[] {email});
share|improve this answer
The problem in the above solution is the hardcoded nature of email address. In my case it can change anytime(due to transfer to another department or etc.). So I have to go back to Sandbox or other means and change it. Scenario: A picklist gets updated on custom object and a mail gets triggered to the internal employee to do a job. Sometime one value gets updated: 2 different mails to 2 different departments. Hopefully you understand my concern. – Rohit May 13 '14 at 11:51
@rohit To solve this problem you need a custom object and Apex trigger with the solution above. – Ashwani May 13 '14 at 17:18
Sorry for late reply. I am doing the same Regal. Thanks. But my problem is that I have to send different mails at different steps so different template. Then how can I send mail after fetching template ID to them. Any solution. – Rohit May 15 '14 at 5:58
Template ID can only be chosen in case of lead/contact. Right? If I am wrong please correct me. – Rohit May 15 '14 at 6:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.