HOW TO QUERY SALESFORCE ATTACHMENTS / EMAIL ATTACHMENTS / CHATTER FEED FILES USING APEX? | Techila
1917
single,single-post,postid-1917,single-format-standard,ajax_updown_fade,page_not_loaded,,qode_grid_1300,footer_responsive_adv,hide_top_bar_on_mobile_header,qode-content-sidebar-responsive,qode-theme-ver-9.4.2,bridge,wpb-js-composer js-comp-ver-4.12,vc_responsive
 

HOW TO QUERY SALESFORCE ATTACHMENTS / EMAIL ATTACHMENTS / CHATTER FEED FILES USING APEX?

HOW TO QUERY SALESFORCE ATTACHMENTS / EMAIL ATTACHMENTS / CHATTER FEED FILES USING APEX

HOW TO QUERY SALESFORCE ATTACHMENTS / EMAIL ATTACHMENTS / CHATTER FEED FILES USING APEX?

There are quite a few ways content (files) are stored in Salesforce. This article shows you ways to access them through a SOQL query.

EMAIL ATTACHMENT:

Let’s consider the scenario where we have attachments against email messages related to a Case. Let’s see how to query it in SOQL.

EMAIL ATTACHMENT

SOQL Query:

Assuming case number 123

Case cs = [Select Id from Case where CaseNumber=123];

Map<Id,EmailMessage> caseEmails = new Map<Id,EmailMessage>([Select Id from EmailMessage where ParentId=:cs.Id and HasAttachment = true]);

Set<Id> caseRelatedIds = new Set<Id>();

if(caseEmails != null){

caseRelatedIds.addAll(caseEmails.keySet());

}

List<Attachment> AttachedFiles = [SELECT Id, Name, Body, ContentType FROM Attachment WHERE ParentId IN :caseRelatedIds];

ATTACHMENTS against a Case:

ATTACHMENTS against a Case

Case cs = [Select Id from Case where CaseNumber=123];

List<Attachment> AttachedFiles = [SELECT Id, Name, Body, ContentType FROM Attachment WHERE ParentId IN =:cs.Id];

Salesforce Files Attached to a Case Feed:

Salesforce Files Attached to a Case Feed

Case cs = [Select Id from Case where CaseNumber=123];

List<CaseFeed> caseChatterFiles = [SELECT Id, Type, Body, Title, LinkUrl, ContentData, ContentSize, ContentFileName, ContentType From CaseFeed where Type = ‘ContentPost’ and parentId = :cs.Id];

 Courtesy:  http://www.forcetree.com/2016/10/query-salesforce-attachments-files-apex.html

https://tctechcrunch2011.files.wordpress.com/2013/09/big_query_logo.png?w=400

“Know more about Salesforce Consulting at Techila”

Author: techila

No Comments

Post A Comment