0

我需要将 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;
}  

}

4

1 回答 1

0

这是我最终使用的:

trigger AttachFileToAccountFeed on Attachment (before insert) {   
    ID accountId; 
    list<FeedItem> listOfFeedFiles = new List<FeedItem>(); 

    if(Trigger.isBefore){

        for(Attachment attachment : trigger.new) {
            // ensure the Id is an Account Id
            if(attachment.ParentId.getSObjectType() != Account.SObjectType)
                continue;

            // ensure file contains Signed Authorization in File Name
            if(attachment.Name.contains('Signed Authorization')) {

                //Adding a Content post
                accountId = attachment.ParentId;
                FeedItem post = new FeedItem();
                post.ParentId = accountId;
                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;
    }  

}
于 2016-03-23T19:28:43.303 回答