Skip to main content

Questions tagged [singleemailmessage]

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

105 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
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
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
3 votes
0 answers
176 views

SingleEmailMessage Sends Email, but EmailMessage not associated With the Case

I'm using the following code to create a list of Messaging.SingleEmailMessage: List<Messaging.SingleEmailMessage> emailNotifications = new List<Messaging.SingleEmailMessage>(); for (Id ...
Ron Van Aken's user avatar
3 votes
0 answers
2k views

How to send Case Emails to Users via Apex

Note: this question has been significantly edited after I discovered a new, more immediate issue with this scenario. My use case: A Case may be created via Internal User, Community User, or Email-to-...
Jason Clark's user avatar
3 votes
1 answer
1k views

Understanding EmailMessage for Data Migration

As I attempt data migration from one Salesforce org to another, I am finding EmailMessage to be a very unnecessarily complicated object to understand. At one point I thought I understood that recent ...
Xtremefaith's user avatar
  • 4,570
3 votes
0 answers
2k views

Apex Email result isSuccess true but not receiving any email

I am trying to send automatic reminder emails about approvals which have been waiting over 2 days. So I created a schedulable apex to check ProcessInstanceWorkItems and send email to approver and ...
Barış Arslan's user avatar
3 votes
0 answers
142 views

Clarification on SingleEmailMessage changes in Winter '16

Anyone knows the implications of this new method? setTreatBodiesAsTemplate(treatAsTemplate) Optional. If set to true, the subject, plain text, and HTML text bodies of the email are treated as ...
Mossi's user avatar
  • 3,996
2 votes
0 answers
208 views

Converting Rendered Email Templates to PDFs - issue(s)

I'm hoping someone here will be able to help me as I have been trying different "solutions" for days now...to no avail. I am new to Apex and do have some Java in my backgorund...not much ...
greeng13's user avatar
2 votes
1 answer
698 views

System.TypeException: "emailSimple" isn't a valid action type

I am trying to use an standard Invocable Action "Send Email" from my apex code with the following snippet: Invocable.Action action = Invocable.Action.createStandardAction('emailSimple'); ...
Gabriel Serrano Salas's user avatar
2 votes
2 answers
925 views

How can I bulkify EmailMessage insert when sending mass SingleEmailMessage

I am having an issue with bulk sending bulk emails, that then insert as emailmessage, even if I do a bulk send of emails when it goes to insert the emailmessage it is doing a single insert for each ...
Michael's user avatar
  • 320
2 votes
1 answer
3k views

Messaging.renderStoredEmailTemplate() is rendering Visualforce email template without custom header

Messaging.renderStoredEmailTemplate() is rendering Visualforce email template without custom header. I have a requirement to send an email with custom header. So created a visualforce email template ...
Satheesh Kumar Natesan's user avatar
2 votes
0 answers
2k views

How to add cc & bcc in Messaging.SingleEmailMessage Email and simultaneously avoid single Email limit being hit

My requirement is to send single email with To/Cc/Bcc added. All the email Ids belong to internal users. Initially, when I was passing the User.Id to these methods, I was hitting the Single Email ...
TheThinkingMan's user avatar
2 votes
0 answers
141 views

Email Relaying Not Working When email is sent from Apex

Our application has a few features where we allow the user to generate documents and send emails. This is all custom lightning components and apex code. We send the emails using SingleEmailMessage. ...
Zack Walton's user avatar
  • 1,626
2 votes
1 answer
3k views

Community Profile User unable to send APEX emails

I have a class containing this method that creates an email in APEX and sends it out once the method is called. public static void generateMessagingTemplates( String requestLogId){ String ...
Art S's user avatar
  • 311
2 votes
0 answers
296 views

which is best approach for custom email alerts, Declarative vs Programmatic?

Object_A and Object_B are two related(Lookup) objects in Salesforce, where A is parent and B is child. Requirement is, when a new Object_B record is created, an email alert should be sent to Object_B ...
Azeez's user avatar
  • 103
2 votes
0 answers
63 views

Flow sending 600 emails to single contact

I have a flow that is being called via Apex. The flow is taking in a list of a custom object called "Milestones". The flow has a wait element that waits for 10 days and then recalls another Apex ...
Rufio0425's user avatar
2 votes
1 answer
4k views

SingleEmailMessage: adding a name and address on setReplyTo

When sending emails, I'm using the mail.setReplyTo() method to provide the Reply-To address: ... mail.setReplyTo('[email protected]'); ... Which results on the next email sent (headers): From: ...
asolfre's user avatar
  • 21
1 vote
0 answers
36 views

Why would setting "save as activity" to true throw "duplicate value found" exception when sending an email with a template?

First thing first, I have gone through this thread where "duplicate value" is discussed - How to debug the mysterious "duplicate value found: <unknown> duplicates value on record ...
Mitesh Sura's user avatar
1 vote
0 answers
147 views

Issue with attachments when resending an e-mail (that belongs to a Case) via Apex

I have an Apex batch job that periodically resends mails that belong to Cases. It creates a SingleEmailMessage, copies all relevant fields from the previous, most recently sent, EmailMessage and sends ...
Sander de Jong's user avatar
1 vote
0 answers
106 views

Can read receipts be used with emails sent from Apex?

Are we able to track if emails sent through Apex code are read/opened? Sending emails via Messaging.SingleEmailMessage creates an EmailMessage record but does not track when I open it like a email ...
UserIsStuck's user avatar
1 vote
0 answers
259 views

SendEmail failed.[...] first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY when Messaging.sendEmail via guest user on a site

We have a public site which uses a guest user to execute the logic of all its aura components/classes... We are facing an issue when this guest user tries to send an email through Messaging.sendEmail(...
Arnau LS's user avatar
1 vote
0 answers
484 views

Attachments sent from Apex are not stored in the EmailMessage record or the parent Case record

I'm using `<lightning-file-upload label="Attach files" name="fileUploader" accept={acceptedFormats} ...
User2529's user avatar
  • 713
1 vote
0 answers
517 views

Filling custom fields when sending emails

Although custom fields can be added to the standard EmailMessage object, there does not seem to be any way to populate these fields when sending an Email using the Messaging.SingleEmailMessage class. ...
John Lewis's user avatar
1 vote
1 answer
355 views

Send Email to list of Contacts in Cases

I have a problem writing an Apex class which will send the emails to the list of Cases based on specified criteria from scheduled flow. Here is my code: public class EmailClass { @InvocableMethod ...
NewToApex's user avatar
1 vote
0 answers
153 views

How to show "From Name" in Email Template

I want to show specific From Name in the email template as I have more than one record in the Org wide address. Can anyone help how to do it? Note : I am always getting the current logged in user name ...
SF Dev's user avatar
  • 43
1 vote
0 answers
672 views

Messaging.SingleEmailMessage with Template fails, but Messaging.renderStoredEmailTemplate() works?

I'm sending out a singleEmailMessage using a template. The Messaging.SendEmailResult reports success and the email comes through, but the template portion of the email is empty. (The WhatId is ...
Baird Straughan's user avatar
1 vote
0 answers
4k views

SendEmail failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY

I have custom LWC page as Public Site, In my Page i will be collecting the Name and Email address, On clicking send will insert the data in Custom Object and will send an Email to an given Email ...
SK2889's user avatar
  • 929
1 vote
0 answers
1k views

Email Message record creation through process builder

I want to create an email message record after sending an email template. Is there any way to create email message record through process builder or workflow after sending an email alert. So that we ...
bainubelli hari's user avatar
1 vote
0 answers
2k views

Email Limit on Scratch Org?

Working in SFDX with a scratch org. I'm setting up a future method to send an email if it fails, trying to get the formatting right, and testing. Now, I've hit a wall: SINGLE_EMAIL_LIMIT_EXCEEDED, ...
PatMcClellan__c's user avatar
1 vote
0 answers
819 views

Messaging sendEmail Issue

I'm using a single email message to send an email. When we tried to sent an email with a wrong email address on newly created lead record. I'm getting message result success is true. But the same ...
user10286's user avatar
  • 422
1 vote
1 answer
1k views

SingleEmailMessage issue

Could someone look into this code, and let me know if they see anything wrong that may be causing a problem? For some reason my email is being successfully send with HTML version, but the text version ...
Ivo Dimov's user avatar
  • 357
1 vote
0 answers
227 views

Salesforce Contact Opt out (Messaging.SingleEmailMessage.setOptOutPolicy) is not working for User's ID

I am trying to use salesforce opt-out feature via APEX code. According to the doc, Salesforce should respect the opt-out field of contact if we use the ID of an object as a target. When I am using ...
Sanjay Kharwar's user avatar
1 vote
1 answer
2k views

Does creation/update of an EmailMessage record ever send an actual email?

I suspect the answer is no, that one would need to use an unrelated call such as sendEmail() or something like that to actually send a message. That said, I'm in the process of doing a data ...
Smitty's user avatar
  • 111
1 vote
0 answers
2k views

Email Template not working

I'm trying to send an Email with an attachment and a template. EmailTemplate emailTemplate = [Select Id from EmailTemplate where Name = 'Test Mail']; List<Messaging.SingleEmailMessage> allmsg =...
nverm's user avatar
  • 199
1 vote
2 answers
335 views

Retrieving EmailStatus for Email related to Account

We are creating an email via Apex code: for (LeadOrContactTarget contact : contacts) { Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); mail....
Edmondo's user avatar
  • 1,712
1 vote
0 answers
1k views

Creating 'Add to Calendar' Link, or Accept/Decline formatting in email?

In gmail, when you get invited to an event, you get emails like this: I am assembling emails to send to all invitees of an event with an email template in apex (template is in email template folder ...
Tyler Dahle's user avatar
  • 2,729
1 vote
0 answers
497 views

Is it possible to set an Event to the WhatId of SingleEmailMessage?

Is it possible to set Event to the whatId of a SingleEmailMessage? I created a dummy contact with a first name, last name, and email, then inserted it, then set that contact's Id to setTargetObjectId()...
Tyler Dahle's user avatar
  • 2,729
1 vote
0 answers
1k views

Pass relatedTo value from Apex Code to VF Email template

I have a VF email template where the recipientType is contact and the relatedTo is case. I'm creating a singleeEmailMessage from Apex Code and I want to use above email template. I know I can set the ...
L Mudiyanse's user avatar
1 vote
0 answers
766 views

Subscript is invalid because list is empty: In Trigger

I implemented one trigger in Parent object.I am getting the following error while creating child record. Error: Invalid Data. Review all error messages below to correct your data. Apex trigger ...
Sfmcprgmr's user avatar
  • 439
1 vote
0 answers
1k views

Setting the Sender name in outgoing email

I am trying to change the Sender Name in an email that i am sending using apex. I would appreciate it if some one can help me understand how salesforce sets the sender's name in an email. Here is my ...
Rohitha's user avatar
  • 85
1 vote
1 answer
47 views

How to send email without relationship between two objects

i am implmented one trigger for If multiple student records and/ or multiple student email records found, send email to student.course having multipul student records based on coursename field. here ...
Test SFDC's user avatar
1 vote
0 answers
387 views

Timezone conversion for datetime field in html emailtemplate in apex using messaging.renderStoredEmailTemplate

I am using html email template in apex to send email to users.The htmlemailbody is rendered by using messaging.renderStoredEmailTemplate method.I am getting correct emailbody but i am not able to ...
Preya's user avatar
  • 583
1 vote
1 answer
4k views

Setting a from address in SingleEmailMessage not by organisation wide email address

I have a requirement where the ‘from address’ need to be changed . According to business logic cannot use “Organization wide email address” When ever the record is updated , From address should ...
nam's user avatar
  • 103
1 vote
1 answer
174 views

SingleEmailMessage with public sites user throwing error

is anyone using a public site and sending an email with this public sites user through an apex class with the SingleEmailMessage Method. It always worked very well but since some time i get the error ...
Peter Pospisil's user avatar
1 vote
1 answer
945 views

Get ActivityId From SingleEmailMessage

When sending a SingleEmailMessage from apex to a Contact, activities are automatically created for that Contact. I also want to log an activity on records that are related to this email. I can't use a ...
Sean's user avatar
  • 646
1 vote
0 answers
679 views

salesforce changes parent id of email Attachment to Case Id eventhough I set it to EmailMessage's Id

I am trying to create an Attachment with ParentId as the EmailMessage's Id but salesforce somehow changes it to the Case Id. I need the ParentId to be EmailMessage Id as I want to select attachments ...
frank's user avatar
  • 31
1 vote
3 answers
5k views

Not able to send email using Messaging.sendEmail if I am Community Guest User

Requirement: Take input (Name, Phone) from user into LWC modal and on click of submit button fire email, using Apex Messaging class, if user is Community Guest User. Current Issue: When logged in as ...
Aastha 's user avatar
0 votes
0 answers
69 views

Why Email Logs are empty when the email has been queued from Apex?

There is an Apex method that sends a SingleEmailMessage. List<Messaging.SendEmailResult> results = Messaging.sendEmail(new List<Messaging.SingleEmailMessage>{message}); It has been ...
Duck The Developer's user avatar
0 votes
0 answers
36 views

What is the difference between SingleEmailMessage and MassEmailMessage?

While i'm sending Email for 30 records both are getting Limit exceed Exception Through Batch apex i give batch size as 10 but still getting exception.This is my code global class ...
user147601's user avatar
0 votes
0 answers
491 views

Apex error SendEmail failed. First exception on row 0; first error: UNKNOWN_EXCEPTION, null

On Wednesday 10/4/23 about 2pm EDT, I suddenly started getting runtime errors from salesforce: SendEmail failed. First exception on row 0; first error: UNKNOWN_EXCEPTION, null only when the logged ...
Michael Robert's user avatar