28 votes

How to Test Messaging.sendEmail

You can use the Limits.getEmailInvocations method . Test.startTest(); methodThatSendsEmail(); Integer invocations = Limits.getEmailInvocations(); Test.stopTest(); system.assertEquals(1, ...
user avatar
  • 143k
22 votes
Accepted

Making regex case-insensitive

You need to use JAVA-like CASE_INSENSITIVE pattern (?i) Something like this: Pattern staPattern = Pattern.compile('(?i)STA[0-9]{4}');
user avatar
  • 21.7k
13 votes
Accepted

How to Test Messaging.sendEmail

With respect to your edited question, as @AdrianLarson answered, your schedulable class still doesn't run until immediately after Test.stopTest(). Asserting the change in Limits.getEmailInvocations() ...
user avatar
  • 40.4k
12 votes
Accepted

Can't activate Email Service

After speaking to Salesforce support I have resolved the issue. Rather than delete the post i will answer it incase anyone has similar issues... The support consultant literally took a copy of my ...
user avatar
  • 1,164
9 votes
Accepted

Differences between email to case and on demand email to case

The email to case is a java process that reads all of the data in the email and then assigns pieces to various fields in SF and then does an Insert or Upsert into the SF system. Because the email is ...
user avatar
  • 410
9 votes

Salesforce Email Service Debugging

The likely answer comes from the comment by @MarcDBehr Email Services can have several Email Addresses. Each Email Address has a context user (i.e. running user) You need to enable debug logging for ...
user avatar
  • 62.2k
8 votes
Accepted

Do email results come in the same order as the list of emails

To answer the specific question, the sendEmail method returns a list of Messaging.SendEmailResult objects. This list will be in the same order as the corresponding list of emails provided to sendEmail(...
user avatar
  • 62.2k
8 votes

Issue Setting ContentVersion Owner

Add this line: newContentVersion.firstPublishLocationId= user.Id; A more detailed explanation: When documents are created via apex (contentversion object), you need to specify the library otherwise ...
user avatar
  • 522
8 votes
Accepted

How to leverage org-wide email address within an email service?

2 options: Option 1 1) Create a class which implements the inboundHandler. global class VerifyOrgWideEmailAddress implements Messaging.InboundEmailHandler { global Messaging....
user avatar
  • 4,323
7 votes
Accepted

How to override the FROM Email in Messaging.SingleEmailMessage

As @crop1645 mentioned, the error message is fairly clear in this case. When you specify the Org-Wide Email Address you're sending the message from, you will not be able to also set the Sender Display ...
user avatar
  • 3,289
7 votes

How can I convert my htmlBody to plainTextBody using Apex/Regex

I think rather than using any RegEx, you can just use a built in String method: stripHtmlTags. Salesforce String Class So it would look like: String plainText = htmlBody.stripHtmlTags();
user avatar
7 votes
Accepted

Regex including curly brackets

Since backslashes are the escape character in Apex string literals, if you want a literal backlash, you need to escape it with a backslash. So the right regex to use would be \\{.*\\}
user avatar
  • 48.1k
6 votes

How to unzip a zipfile attachment in apex and process each file in the zip attachment

You can do this natively in Apex using the Zippex library which is open source. https://github.com/pdalcol/Zippex Your code would be similar to this: Blob zipBlob; //This needs to contain the zip ...
user avatar
6 votes

How to test if outbound email is send

In addition to the other answers, there is ApexMocks and the fflib Enterprise Pattern - specifically the Unit of Work Layer Here's an example: First, the class/method that sends the email: public ...
user avatar
  • 62.2k
6 votes
Accepted

Test Coverage for a Email Services Class

In your EmailServices class, you have this line: @testVisible Opportunity opp = new Opportunity(); You are apparently trying to query the value of this variable in your testmethod to see if it is ...
user avatar
  • 62.2k
6 votes
Accepted

How to use an Apex Email Service to store emails on a record EXACTLY as Salesforce does?

From what I understand, You don't need to create a task to insert an EmailMessage. Email message has relatedToId field which you can use to directly link it to any desired record. As relatedToId is ...
user avatar
6 votes
Accepted

Regex implementation in Salesforce: getting from known string to end of the line

You need to turn on multi-line mode in order for the $ specifier to match at a line terminator (rather than at the end of the string). Multi-line mode is activated with the token (?m). As Derek F. ...
user avatar
  • 86.8k
5 votes

How to test if outbound email is send

Are you aware of mocking the messaging service? I have an interface with a method sendEmail. In the live code I provide a concrete implementation of the interface which actually sends the email. In ...
user avatar
  • 3,162
5 votes

How to test if outbound email is send

When SFDC is executing testmethods, it will not send any outbound email. This is for a good reason as testmethods would otherwise run the risk of spamming users. Thus, creating an inbound emailservice ...
user avatar
  • 62.2k
5 votes

Differences between email to case and on demand email to case

On-demand email to case is a good option if you know Email attachments (if any) won't be greater than 25MB in size You are not concerned about keeping the emails traffic within your firewall You won'...
user avatar
  • 5,537
5 votes

Not able to receive inbound emails from yahoo

This is as per Yahoo's DMARC policy. I presume you are getting a response similar to this This message was created automatically by the mail system. A message that you sent could not be ...
user avatar
5 votes
Accepted

Error: Compile Error: Initial term of field expression must be a concrete SObject

opp is an array, and you're trying to use it like a single record. You actually meant to write: String[] bccEmail = new String[]{opp[0].owner.email};
user avatar
  • 433k
5 votes
Accepted

List has no rows for assignment to SObject: Publish

You tried to use the result of SOQL query in your code, but this result is not guarantied. In some case your query can return null. So, when you tried to use null.Email you got this error. To fix it ...
user avatar
5 votes

Apex: HTML email status to get open count

The EmailStatus object is not queryable directly (please vote for this idea), but it can be queried indirectly from Leads and Contacts as a child relationship sub-query as noted by Jenny Bennett on ...
user avatar
  • 3,976
5 votes
Accepted

custom Email Service - inline images appear as '[Image is no longer available]' upon Reply/ReplyAll

This is how I solved the problem, after saving off the attachments then I updated the message body to replace the cid references with URL to the files. For some magical reason, Salesforce will ...
user avatar
  • 3,976
5 votes
Accepted

Can an Apex Email Handler parse an attached Excel file?

Short Answer: No its not posssible to read Excel in Apex. Long Answer: Excel files(xls,xlsx etc) are not a text based file. They are binary files. Thus unlike CSV(text based) they cant be read line ...
user avatar
5 votes
Accepted

Create a Salesforce file from an email attachment

Salesforce files have superseded attachments. A single attachment can have only one parent and access to attachments is controlled by the parent record. If we want to attach same file on two different ...
user avatar
5 votes
Accepted

Inbound Email handler - Status being set as 'Sent' instead of 'New'

I think you can set the status value with the sequence number. 0 - New 1 - Read 2 - Replied 3 - Sent 4 - Forwarded 5 - Draft So it could be like this EmailMessage emailMessage = new EmailMessage();...
user avatar
  • 1,617
5 votes
Accepted

Apex SingleEmail using template and userId

This is expected behavior the User fields you are referencing are the sending user fields User fields are also known as Sending User fields for administrators and users with the “Manage Users” ...
user avatar
  • 368
4 votes
Accepted

Inbound email missing attachment?

When you add (or edit) the email handler class via the email service definition you get a choice of what sort of attachments should be passed to it as shown below. Check that setting.
user avatar
  • 130k

Only top scored, non community-wiki answers of a minimum length are eligible