我需要将 Salesforce 中的客户附件自动添加到客户聊天源。我有以下代码,它为每个对象添加了一个聊天帖子,而不仅仅是帐户附件,我怎样才能使其特定于帐户?或者我怎样才能使它特定于某个文件名?
trigger AttachFileToAccountFeed on Attachment (before insert) {
ID accountId;
list<FeedItem> listOfFeedFiles = new List<FeedItem>();
if(Trigger.isBefore){
for(Attachment attachment : trigger.new){
string checkIfAccount = string.valueof(attachment.description);
{
//Adding a Content post
accountId = attachment.ParentId;
FeedItem post = new FeedItem();
post.ParentId = accountId; //eg. Opportunity id, custom object id..
post.Body = 'Attachment added';
post.Type = 'ContentPost';
post.ContentData = attachment.body;
post.ContentFileName = attachment.Name;
post.Title = attachment.Name;
listOfFeedFiles.add(post);
}
}
}
if(listOfFeedFiles!=null){
insert listOfFeedFiles;
}
}