You need to sign in to do that
Don't have an account?
Wei Dong 10
How to fetch attachments through an EmailMessage
Hi,
I have created an EmailMessage, but I cannot fetch the name of the attachments through "EmailMessage.Attachments", so how? Any examples?
I have created an EmailMessage, but I cannot fetch the name of the attachments through "EmailMessage.Attachments", so how? Any examples?
Please use the following query :
SELECT id,name FROM Attachment WHERE ParentId IN (SELECT Id FROM EmailMessage WHERE ParentId = '')
Please let me know if its work for you.
1. I created an EmailMessage and handle the after insert trigger, so the ID is created:
2. Then I attach a file jpg into the email, and click "Send", by referring this code like this:
3. But nothing is shown to me?? Error: List out of bounds.
Should be 'ID = 02s0m000000asfSAAQ'. But still nothing is shown :(
I also tried for an emailmessage with the attachment, but nope, attachments is empty……But actually I have the value!!!
Please put the case Id in ParentId field, let me know if it will work.
Even if I used what you said——CaseID, it still doesn't work :(
The result is:
This is the case:
Try querying from ContentDocumentLink instead ofAttachment.
Query : SELECT ContentDocumentId,Id FROM ContentDocumentLink WHERE LinkedEntityId IN (SELECT ID From EmailMessage WHERE ParentId = <Case Id>)
ContentDocument stores the body, type, size, etc. of the attached file.
Let me know if this works for you.
Thanks
Please refer below queries that might help you to fetch the attachment:
1. Fetch ContentDocumentId from ContentDocumentLink :
SELECT ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId IN (SELECT ID From EmailMessage WHERE ParentId = '5002w000004XXXXXX')
Note: We need to pass the case record's ID in the ParentID marked as bold above.
2. Then pass ContentDocumentId in below query:
Select Title, FileType,CreatedDate, ContentSize from ContentDocument where Id= 'ContentDocumentId '.
Please close this thread and mark as best if this resolves the issue.
Thanks.
https://retrology.net/how-to-create-a-file-from-an-email-attachment-in-salesforce
I am able to query this: Select Title, FileType,CreatedDate, ContentSize from ContentDocument where Id= 'ContentDocumentId '.
Now I want to create a new attachment on new case using same data from the attachment querried from the above.
Can you please guide me how can I can copy attachment?
Thanks in advance !!!