function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Smita HodiggeriSmita Hodiggeri 

How to Get all the email messages for all the opportunities of particular record type? SOQL?

Hi Community,

I am looking to figure out how do I get a list of all the email messages for the all oppotunities of particualr record type?
Any thoughts are much appreciated.

Many thanks,
Smita 
Best Answer chosen by Smita Hodiggeri
Eswar Venkat 2Eswar Venkat 2
SELECT Id, Subject, TextBody, HtmlBody, FromAddress, ToAddress, CreatedDate 
FROM EmailMessage 
WHERE RelatedToId IN (
    SELECT Id 
    FROM Opportunity 
    WHERE RecordTypeId = '<your_record_type_id>'
)


We Provide Salesforce Interview and Work Support.
Interested People DM. (SalesfoceInterview4uBuddy@gmail.com)

All Answers

Arun Kumar 1141Arun Kumar 1141

Hi Smita, 

You can try this query: 

SELECT Id, Subject, ToAddress, FromAddress, TextBody, HtmlBody, ParentId FROM EmailMessage WHERE ParentId IN (SELECT Id FROM Opportunity WHERE RecordTypeId = '<record type id>' )

 

Mark this as best answer if this helps

Thanks

Eswar Venkat 2Eswar Venkat 2
SELECT Id, Subject, TextBody, HtmlBody, FromAddress, ToAddress, CreatedDate 
FROM EmailMessage 
WHERE RelatedToId IN (
    SELECT Id 
    FROM Opportunity 
    WHERE RecordTypeId = '<your_record_type_id>'
)


We Provide Salesforce Interview and Work Support.
Interested People DM. (SalesfoceInterview4uBuddy@gmail.com)
This was selected as the best answer
Smita HodiggeriSmita Hodiggeri
Thanks @Eswar Venkat this worked like a charm. Thanks @Arun for your time.This didnt work for me.