Questions tagged [singleemailmessage]
Relates to the SingleEmailMessage class, which provides methods for sending single email messages through apex.
352
questions
22
votes
2
answers
11k
views
What's the Advantage of using MassEmailMessage instead of multiple SingleEmailMessage?
I'm scoping out a project that will involve sending outbound email messages, and I'm a little confused about why one would use a MassEmailMessage instead of multiple SingleEmailMessages.
If you look ...
18
votes
3
answers
64k
views
How to send an Email Template via Apex?
Goal
I'm attempting send a good looking HTML from Apex code, here's a stripped back screenshot .
Based on the documentation I've reviewed, with Apex we can leverage SalesForce email templates using ...
16
votes
7
answers
26k
views
single email limit exceeded salesforce very frequently..?
my email limit is exceeded after sending 10-12 emails..what could be the problem..as i have seen the limit is 1000 emails/day.i am not able to find out what could be the problem..Can some give me some ...
11
votes
3
answers
18k
views
SingleEmailMessage - send email to a recipient different from the record referenced by setTargetObjectId
My code is as follows:
List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage ();
...
8
votes
3
answers
5k
views
Can't set toAddresses on email when templateId defined?
Question
Did something change recently with the SingleEmail methods that prevents using setToAddresses() when a template is used?
Background
I need to send an email to a user based and pass in the ...
8
votes
1
answer
2k
views
Detect if Compliance BCC Email is enabled
Problem:
If the Compliance BCC Email setting is enabled email messages cannot be sent with custom BCC addresses e.g.
Messaging.SingleEmailMessage toSend = new Messaging.SingleEmailMessage();
toSend....
8
votes
1
answer
10k
views
Long Text field in Report Workaround
So I know that Rich/Long text fields will automatically get truncated when running a report in the UI or when trying to schedule a report. I get this and think this is something that should be in ...
8
votes
1
answer
2k
views
How to debug Post-Install script?
We don't get much information on email received by subscriber if Post-install script fails.
Problem:
Unexpected Error
The package installation failed. Please provide the following
...
8
votes
2
answers
865
views
Ignore user context while sending SingleEmailMessage
Can we send SingleEmailMessage(s) under admin context and ignore current user sharings and profile access.
Details:
- visualforce email template is related to object B which is not available for users ...
7
votes
2
answers
1k
views
Messaging.SendEmailResult Type cannot be constructed?
I'm trying to create a simple mock of messaging Messaging.sendEmail and in my code I'm trying to do the following to construct mocked instances of Messaging.SendEmailResult
Messaging.SendEmailResult ...
7
votes
2
answers
1k
views
Do email results come in the same order as the list of emails
I populate a list of emails emailsToBeSent and send them all at once. However These emails are related to different sObjects. And to me it is important to know which sObject the returned results are ...
7
votes
3
answers
6k
views
For the Platform Event "Automated Process" user, why do both Visualforce controller access and email sending fail?
We are executing some asynchronous code that uses getContentAsPdf on a Visualforce page as the result of handling custom platform event and we get this error in the Apex Jobs listing:
First error: [...
7
votes
3
answers
1k
views
How many single email messages with visualforce templates can be sent in a single transaction?
If I need to send a huge amount of emails to 500+ contacts, each email using one of three visualforce templates (syntax needed for translations is available only on Visualforce templates, with ...
7
votes
2
answers
5k
views
WHY Can't I Use SetTargetObjectId(UserId) and SetWhatId?
I have a very simple error handling case. I need to send an email to the running user, who almost certainly does not have an associated Contact record. I also need to specify the error record in ...
7
votes
1
answer
494
views
gmail email relay work around or alternatives
I was wondering what other organizations using gmail have done for email relaying with Salesforce. My organization will not be removing the gmail authentication so I was wondering if there is a work ...
7
votes
0
answers
830
views
How to use SingleEmailMessage.setReferences Method
According to the documentation, the setReferences function "Identifies an email thread. Contains the parent emails' References and message IDs, and possibly the In-Reply-To fields".
I can't actually ...
6
votes
2
answers
4k
views
System.LimitException: Too many SOQL queries: 101
I am calling sendemail() from visualforce.There are no SOQL Queries inside for loops but am getting error in controller.
If I comment below two lines then am not getting error
Messaging....
6
votes
2
answers
1k
views
unable to get excel file in proper format when sending email
I had used in the controller:
a.setContentType('application/vnd.ms-excel');
but when i clicked a button to send the email with an attachment, i am getting all fields in one row.
How can i solve ...
6
votes
2
answers
4k
views
How to get the Id of an EmailMessage after sending a SingleEmailMessage with Messaging.SendEmail()?
Is there any way to easily retrieve the Id of EmailMessage records after sending them via Messaging.SendEmail()?
Messaging.SingleEmailMessage m = new Messaging.SingleEmailMessage();
m.setToAddresses( ...
6
votes
1
answer
7k
views
Not Serializable: com/salesforce/api/fast/List$$lcom/salesforce/api/Messaging/SingleEmailMessage$$r
There was a similar question asked here, but it wasn't really answered.
I've got a function that sends an e-mail for the User from a Visualforce Page, pretty simple:
Visualforce Page
<apex:...
6
votes
1
answer
7k
views
How to test SendEmailResult for SingleEmailMessage
How could I write unit tests for the SendEmailResult. I want to generate erros in to errResult parameter. What are the possible ways of testing this.
Messaging.SingleEmailMessage message = ...
6
votes
1
answer
7k
views
SingleMessage with TemplateId in Apex: need to add more recipients
I am writing code to send emails to contacts via Apex using templates. My issue is that I need to be able to copy these emails to various other users that are going to be determined at run time. This ...
6
votes
1
answer
892
views
How to deep clone Messaging.SingleEmailMessage?
Problem Statement
I'm working on a fluent email builder, but I've hit a bit of a snag. Namely, there does not seem to be any simple way to completely clone a Messaging.SingleEmailMessage instance ...
6
votes
2
answers
2k
views
Single Email Message bulkification is not working in Apex
Description: When I deactivate multiple users, say a,b,c, the following code is triggered to send emails to their respective managers. but in my case the manager receives the email with only the ...
6
votes
1
answer
2k
views
Emails are not being received when sent through Apex
Below is my sendEmail Method .
public void sendMail(List<user> Users, string emailTemplateName) {
final string FROM_ADDRESS ='Test';
List<Messaging.SingleEmailMessage> emails = new ...
5
votes
3
answers
5k
views
Send mail to the System Administrator
I have tried this to send mail to the logged in user
String[] toAddresses = new String[] {UserInfo.getUserEmail()};
mail.setToAddresses(toAddresses);
This works fine for the users who have logged in,...
5
votes
1
answer
7k
views
LetterHead in Apex
Is it possible to access LetterHead in apex.I need to put the letter head in sethtmlbody method.How to access LetterHead.
UPDATED
Here the bt.value is displaying blank when contact is receiving an ...
5
votes
1
answer
139
views
Streaming API not working when email is sent from Apex Batch
I have a Batch class that updates Last_Date__c on Project__c object in the Finish method.
I have a PushTopic 'LastDateUpdate' on Project__c which is fired when Last_Date__c is updated.
I'm ...
4
votes
1
answer
9k
views
Files as email attachment from Apex
We have a requirement to send email with attachment.
When a Opportunity stage is changed need to send a email to opportunity owner with attachments(Files added to that opportunity).
This work fine ...
4
votes
3
answers
3k
views
How to set time limit between queued jobs?
So I am looking to implement Queueable jobs in apex to send 200 emails (1 job) every 30 minutes until all the jobs are done, I am struggling to find any documentation on how this functionality can be ...
4
votes
1
answer
6k
views
In Messaging.SendEmailResult what does the errors attribute contain?
I'm sending multiple emails using Messaging.sendEmail. After that I'm checking for the results by looping over the List<Messaging.SendEmailResult> just like the example below. Now my question is:...
4
votes
1
answer
9k
views
Test class Limits.getEmailInvocations() showing zero and assertion is failing
I have a bizarre issue. I have a trigger that will send an email based upon a record update. When I debug my trigger running the test class it showing the email result as success and when I debug and ...
4
votes
1
answer
2k
views
How does setTreatBodiesAsTemplate(treatAsTemplate) work?
I have been unable to find any useful documentation on this method outside of the horrible definition that SalesForce gives it that gives you no indication of what it actually does for you.
What use ...
4
votes
1
answer
8k
views
setsaveasActivity
I am trying to send an email to Order Contact and Order Owner and saving it as Completed Task(Activity History) against Order but Sent Email is saved against Contact's Activity History.How to save it ...
4
votes
1
answer
3k
views
Messaging.sendEmail not sending emails for non-admin profile in sandbox
In a partial sandbox I am calling Messaging.sendEmail through an @InvocableMethod through a Flow, and emails are not going out for a non-admin profile. There are no errors anywhere and even debugging ...
4
votes
1
answer
4k
views
Why does Messaging.renderEmailTemplate() return a "Field Custom_Field__c does not exist" even when the field does exists?
When running the code below anonymously I get a (paraphrased) error:
"Field Custom_Field__c does not exist"
Code:
Id bankId = 'a1e630000000oOG';
Id contactId = '00363000009GnPE';
//verify ...
4
votes
1
answer
1k
views
Does sending SingleEmailMessage with template use a SOQL query?
I'm getting a somewhat strange error message when trying to send a list of emails
System.EmailException: SendEmail failed. First exception on row 11;
first error: LIMIT_EXCEEDED, System....
4
votes
1
answer
148
views
dailly email limits
I have gotten this error in production
SINGLE_EMAIL_LIMIT_EXCEEDED
I am sure i have maxed out the daily email limit of 1 000
limit info
https://help.salesforce.com/HTViewHelpDoc?id=...
4
votes
1
answer
3k
views
Email not being send if whatID is set and setSaveAsActivity is true
I have the following code
if (this.templateId != null) {
// parameters specific for visualforce template
singleEmailMessage.setTargetObjectId(this.targetObjectId);
...
4
votes
1
answer
1k
views
SingleEmailMessage setReplyTo not working with some clients
Even though the ReplyTo property of SingleEmailMessage is set to a "noreply" address we are still getting emails sent to our admin email. This only happens with certain email clients (e.g. Gmail doesn'...
4
votes
1
answer
990
views
Avoid blacklisting of Org-Wide email address
We are using the apex method Messaging.sendEmail.setOrgWideEmailAddressId() in a schedular class to send emails to our customers, But our concern is when sending internet email.. you never want from ...
3
votes
4
answers
3k
views
Best Practice for Sending Emails via Apex
I'm playing around in my Dev org and am using a trigger to send a basic e-mail to System Admins when an account is created as follows:
private static void doNotifyAdmin(List<Account> acc) {
...
3
votes
1
answer
6k
views
Send an Email functionality in a custom button of a custom object
Is there any way to utilize the email functionality of Send an Email button from Activities related list into a custom object? I'm trying with custom visualforce page and controller but not able to ...
3
votes
2
answers
8k
views
Messaging: setTargetObjectID with custom objects
I have a custom object that have a custom email field. I need to send email to the email address which is stored in that email field.
But as I read we cant use setTargetObjectID with custom objects. ...
3
votes
1
answer
8k
views
sending html email from APEX using templates
When I am doing a test send using the data in the quote object record, I am getting an html formatted email with values.
In the doc: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/...
3
votes
1
answer
1k
views
Email Attachment (CSV) Issue
I have created a batch that will copy some event fields to a csv and attach it to an email. The problem I have is that I failed to replicate some characters (• bullet point, in this case) from the ...
3
votes
4
answers
2k
views
When sending an email template and using the class 'SingleEmailMessage', can the sent email be attached to the case for reference?
When using auto-responders for email-to-case, the outbound emails are attached to the case. I'd like to perform the same action, when I am sending outbound emails via my own inbound email handler.
...
3
votes
1
answer
2k
views
Encoding used when sending emails through singleemail method
When sending out a single email salesforce encodes the HTML body
As per doc :
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_email_outbound_single.htm#...
3
votes
1
answer
384
views
Threading emails onto a lead
I'm working on a project that takes care of sending emails to customers who sign up with us. The project automatically creates a new Lead for every customer that signs up, but we next want to store a ...
3
votes
1
answer
3k
views
Invalid Message Id Reference - In-Reply-To Header is Not Valid
I am designing a custom mail application with Visualforce and Apex in salesforce and I'm running into some issues maintaining threads and setting reply to ids.
To establish which emails are a response ...