Skip to main content

#EmailMessage Object0 discussing

To get data from emails in Salesforce, you can use several methods and tools depending on the specific use case and requirements. 

 

global class EmailService extends Messaging.InboundEmailService {

    global Messaging.InboundEmailResult processIncomingEmail(Messaging.inboundEmail email, Messaging.InboundEnvelope envelope) {

        // Get the email body and subject

        String body = email.plainTextBody;

        String subject = email.subject;

 

        // Extract data from the email body using regular expressions or string manipulation

        // For example, let's extract the customer name and order number

        Pattern pattern = Pattern.compile('Customer Name: (.*?)\n');

        Matcher matcher = pattern.matcher(body);

        String customerName = matcher.find() ? matcher.group(1) : '';

 

        pattern = Pattern.compile('Order Number: (.*?)\n');

        matcher = pattern.matcher(body);

        String orderNumber = matcher.find() ? matcher.group(1) : '';

 

        // Create a new record in Salesforce using the extracted data

        Account acc = new Account(Name = customerName);

        insert acc;

 

        Order ord = new Order(AccountId = acc.Id, OrderNumber = orderNumber);

        insert ord;

 

        // Return a success response

        return new Messaging.InboundEmailResult(success=true);

    }

}

 

 

 

📧 Unlock the power of Salesforce by learning how to extract data from emails efficiently! Our latest blog explores various methods, including Email-to-Case, Einstein Activity Capture, custom Email Services, and third-party integrations. Enhance your CRM experience by automating data capture and improving data accuracy.

Check out the full guide now!

 

https://fetchrecordfromemail.blogspot.com/2024/07/get-data-from-emails-in-salesforce.html

 

#Salesforce Developer #Salesforce #CRM Configuration #Email-to-case  #EmailMessage Object

0/9000

Hello,

 

I'm trying to add the related list from the enhanced email object (emailmessage object) to my contact record pages. I believe I have done this (added a lookup field to contacts on emailmessage object, a related list appeared in contacts, added it to page layout, added it to lightning page layout) however the related list shows 0 emails (there are definitely enhanced emails related to the contact).  Does the email related list work differently than other related lists?

 

Here is what I'm trying to achieve:

 

I'm using Match My Email (MME) for email logging. It has a custom object for importing emails from gmail and a component that lists all of the emails it imports (instead of on the activity timeline). However I also use email-to-case and those emails are stored in the activity timeline. I feel like my users will be confused if the activity timeline shows, tasks, logged calls, events and emails from email-to-case only, while showing all other emails in a separate component.  What I would like to do is only show tasks, logged calls, events in the activity timeline (by using it's filter feature) then show email-to-case emails on the email related list and the MME emails in it's own list.

 

Any suggestions on either how to get the email related list working on contact object or a better idea for showing these different emails/activities?

 

Thx

 

#EmailMessage Object

2 answers
  1. Mohit Kumar Agarwal (Dell Technologies) Forum Ambassador
    Mar 5, 2024, 2:01 AM
0/9000

Hey guys, hope all of you are good.

 

I need help to find a way to block the users from sending blank emails. I already created and tested the following validation rules, but it doesn't worked.

 

1st try: ISBLANK(TextBody)

2nd try: ISNULL(TextBody)

 

#Validation Rule  #EmailMessage Object  #Email Messages

5 answers
  1. Bradley Weller (Fast Slow Motion) Forum Ambassador
    Feb 27, 2024, 11:42 PM

    I expect the issue is that the email message object is basically a log of the email being sent rather than playing a part in initiating the send. Therefore, the Validation Rule could prevent the creation of the email message record, but not the email send.

0/9000

Is it possible to create or access an HTML email template when using the email functionality from within a Salesforce record. See screenshot below

HTML version of email templates availability when emailing from within a Salesforce record.

#Email #EmailMessage Object

4 answers
0/9000

I tried to manually execute the following in Apex Anonymous and the result is returning NULL Case ID. Does anybody know how to use the new case header method?

  #Email #Customer Service #Email-to-case #Case #EmailMessage Object

 

Apex Anonymous 

List<Messaging.InboundEmail.Header> headers = new List<Messaging.InboundEmail.Header>();

Messaging.InboundEmail.Header messageHeader = new Messaging.InboundEmail.Header();

messageHeader.Name = 'Message-ID:';

messageHeader.value = '<BLAPR16MB37478D93BEC69718C9576BEBBF089@BLAPR16MB3747.namprd16.prod.outlook.com>';

headers.add(messageHeader);

Id caseId = Cases.getCaseIdFromEmailHeaders(headers);

System.Debug('JOSEPH DEBUG : caseId ' + caseId);

 

RESULT

 

15:39:52.1 (7718512)|SYSTEM_METHOD_ENTRY|[11]|System.debug(ANY)

15:39:52.1 (7727733)|USER_DEBUG|[11]|DEBUG|JOSEPH DEBUG : caseId null

15:39:52.1 (7735978)|SYSTEM_METHOD_EXIT|[11]|System.debug(ANY)

 

When querying for the record in the EmailMessage for that Message-ID, it exist in the EmailMessage object.

 

SELECT Id, Headers, Subject, MessageIdentifier, ThreadIdentifier, ReplyToEmailMessageId, ParentId, ActivityId, ToAddress, FromAddress

FROM EmailMessage

WHERE MessageIdentifier = '<BLAPR16MB37478D93BEC69718C9576BEBBF089@BLAPR16MB3747.namprd16.prod.outlook.com>'

 

I tried to manually execute the following in Apex Anonymous and the result is returning NULL Case ID. Does anybody know how to use the new case header method? Apex Anonymous List<Messaging.

2 comments
  1. Dec 13, 2022, 6:49 PM

    Is there a existing emailMessage record (with a parentId pointing to a case) with the message identifier matching your example?

0/9000
S Markham posted in #Email

Email Message Reports: Direct Link to View Email (Solution) 

 

Scenario:  Our team's Communications Manager requested a report to easily view all Email Messages logged in Salesforce.  With the new Custom Report Type for Email Messages (delivered Summer '21), we were able to create the report. However there was no "one-click" field that led us directly from the report to each Email Message record — none that we could find, anyway. Here's how we created one.

Email Message Reports: Direct Link to View Email (Solution) Scenario: Our team's Communications Manager requested a report to easily view all Email Messages logged in Salesforce.

[Updated Nov. 2021 per comment from @Irina Rodin. Thank you!]  

 

1. Create the Custom Report Type to Report on Email Activity.

> We chose the following object relationships:  

Email Messages (A) > with or without related records from Contacts (B)  

    

2. Obtain the Salesforce Record ID (for Email Message object records). 

> Where the ID field you'll add to your report is "Email Message ID". 

 

3. Create a custom formula field ("Text" type) for your new Hyperlink Formula Field.  We chose to name our custom field "Link Email ID".

Input the following formula (for Salesforce Lightning users):  

 

 HYPERLINK( 

 "/lightning/r/EmailMessage/" & Id &"/view", 

 "Link to View Email", 

 "_self" 

 

> Where "Link to View Email" is whichever text you'd prefer to appear in your reports.  

 

4. Revise your report, and Save. 

In your custom report for Email Messages, you can now Add column > Link Email ID > Save & Run, and then use the hyperlinked field to quickly access any Email Message records in the report.  

 

Cheers! 

 

#Activities #EmailMessage Object #Email   

#Reports & Dashboards #Custom Report Type   

#Formulas #Hyperlink Formula Fields

4 comments
0/9000

Email 2 Case Critical Update "Disable Ref ID and Transition to New Email Threading Behavior" and sending Emails through Apex gap.

 

Hello guys,

 

New Threading Behavior is a very exciting feature, we want to introduce it ASAP, so we started testing it and I think that we have found a gap. 

From what I understand, the new behaviour works as following:

  • Email is received on E2C.
  • Information from header: In-Reply-To, References are being matched with MessageIdentifier field on EmailMessage object.
  • If values have been matched, then EmailMessage received on E2C is linked to an existing Case (that is Parent of matched EmailMessage). Otherwise, new Case gets created.

This works perfectly fine with responses to Emails created via Standard features (Case auto-response, Send Email quick action) as MessageIdentifier field gets correctly populated for the emails send.

 

However, in our org we have some other complex scenarios where we require to send emails via Apex. We have tested 2 methods from Messaging class:

  • Messaging.sendEmail(emails, allOrNothing) - we send SingleEmailMessage and then create EmailMessage object based on it (connected to Case via ParentId). 
  • Messaging.sendEmailMessage(emailMessageIds, allOrNothing) - We insert EmailMessage as a draft and then send it using this method.

Neither of those ways gives us any opportunity to populate MessageIdentifier field on EmailMessage object, as it seems that this information is not avaliable in Apex. Moreover, it seems that MessageIdentifier is Read Only (if you populate it programatically before inserting the EmailMessage, it is set to '' anyway.

 

Is my reasoning correct? Are there any enchancements to facilitate that scenario planned before "Disable Ref ID and Transition to New Email Threading Behavior" critical update is enforced? Does it mean that responses to EmailMessages sent via Apex won't work with E2C New Email Threading Behavior?

 

CC: @Zakaria Aoujil @Piotr Wyszynski @Dominik Ryczek

5 comments
  1. Jan 5, 2022, 11:54 AM
    • I'm getting : In-Reply-To, References are being matched with MessageIdentifier field on EmailMessage object.
    • Parent Id not getting . I'm getting : In-Reply-To, References are being matched with MessageIdentifier field on EmailMessage object.Parent Id not getting . What to Do ??? So pls guide...
    • What to Do ???  So  pls guide... 
0/9000

Recently (just in the past few weeks), emails from clients (generally sent to the help desk and are within Cases) are being listed in Overdue Tasks.  Naturally, our client services area would like to know: why this is happening  AND when can it be fixed.  Because this is an email message, not a standard task, it's not like it has a due date on it. #EmailMessage Object #Activity Timeline #Activities

2 answers
  1. Oct 27, 2021, 7:22 PM

    I figured it out.  It turns out Email-to-Case was set to:

    • Create a task for each email
    • Each task was set to Not Started

    We solved it by:

    • Changing the Email-to-Task default task status to Completed
    • Using Data Loader to change the Tasks created by cases
0/9000

Under email-to-case scenario, if a contact replies to the email directly from their email account,  Salesforce will create an emailmessage object, associate it with an open activity object and send some email notification to the case owner and maybe perform many other necessary actions. In my case, I have an application that connects to salesforce using rest api. I want my application to reply emails on behalf of a contact of the case using REST api. How should I do it? I've tried creating emailmessage object using REST api. But it seems to me like it inserts a record to the database quietly without any consequences. Although I did see an email message showed up on case, it does not create any activity or send an email notification to case owner. Any thoughts? Thanks.

 

#Email-to-case  #Case  #Email  #Email Notification  #Emails  #Send Email  #Email Alerts  #Email Object  #EmailMessage Object  #Email Message

0/9000

Release Update:

Disable Ref ID and Transition to New Email Threading Behavior

 

Question #1: We only use outbound email functionality (existing Cases) within Email-to-Case. Will this give us the option to disable automatic Case creation when an email is sent to our Email-to-Case address?

 

Question #2: What is/are the field API labels needed on the EmailMessage object we can use for troubleshooting the unique thread identifier?

 

Question #3: Will this address situations where the customer's reply is sent through their own third-party email encryption system? This normally generates an email with their response not including the Ref ID.

0/9000