Skip to main content

Questions tagged [singleemailmessage]

Relates to the SingleEmailMessage class, which provides methods for sending single email messages through apex.

Filter by
Sorted by
Tagged with
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 ...
Scott VonSchilling's user avatar
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 ...
fusion27's user avatar
  • 305
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 ...
miku's user avatar
  • 1,761
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 (); ...
Ray Dehler's user avatar
  • 1,753
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 ...
Ralph Callaway's user avatar
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....
Mgetz's user avatar
  • 288
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 ...
Chris Duncombe's user avatar
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 ...
Pasan Eeriyagama's user avatar
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 ...
Natallia's user avatar
  • 3,231
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 ...
Michael Paler's user avatar
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 ...
Arthlete's user avatar
  • 4,989
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: [...
Keith C's user avatar
  • 137k
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 ...
Renato Oliveira's user avatar
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 ...
Adrian Larson's user avatar
  • 151k
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 ...
julie curry's user avatar
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 ...
NSjonas's user avatar
  • 10.2k
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....
sfdc's user avatar
  • 13.7k
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 ...
PavanFoxPro's user avatar
  • 1,181
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( ...
Uwe Heim's user avatar
  • 28.5k
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:...
Dan Jones's user avatar
  • 7,237
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 = ...
Hasantha's user avatar
  • 2,055
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 ...
hgolov's user avatar
  • 773
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 ...
Adrian Larson's user avatar
  • 151k
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 ...
SFDCDJ's user avatar
  • 1,916
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 ...
Shira's user avatar
  • 69
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,...
DOMINIC EDWARD's user avatar
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 ...
sfdc's user avatar
  • 13.7k
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 ...
d_k's user avatar
  • 1,301
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 ...
Lavanya Sanathkumar's user avatar
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 ...
Nebbyyy's user avatar
  • 848
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:...
Bahman.A's user avatar
  • 878
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 ...
Andrew L.'s user avatar
  • 859
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 ...
Tyler Dahle's user avatar
  • 2,729
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 ...
sfdc's user avatar
  • 13.7k
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 ...
Mossi's user avatar
  • 3,996
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 ...
Shmuel Kamensky's user avatar
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....
NSjonas's user avatar
  • 10.2k
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=...
user2525898's user avatar
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); ...
Anamika's user avatar
  • 73
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'...
Mossi's user avatar
  • 3,996
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 ...
Jit's user avatar
  • 41
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) { ...
Dan Jones's user avatar
  • 7,237
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 ...
Superman's user avatar
  • 337
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. ...
user905's user avatar
  • 261
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/...
Col's user avatar
  • 71
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 ...
Micz Domz's user avatar
  • 695
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. ...
user7120's user avatar
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#...
Rao's user avatar
  • 16.7k
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 ...
Anthony's user avatar
  • 147
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 ...
S.B.'s user avatar
  • 2,131

1
2 3 4 5
8