【问题标题】:Add Account attachment to Chatter Post Automatically自动将帐户附件添加到 Chatter Post
【发布时间】:2015-09-10 21:39:43
【问题描述】:

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

}

【问题讨论】:

    标签: salesforce apex-code salesforce-chatter apex-trigger


    【解决方案1】:

    这是我最终使用的:

    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;
        }  
    
    }
    

    【讨论】:

      猜你喜欢
      • 2021-09-02
      • 2010-10-31
      • 2017-02-13
      • 2022-01-03
      • 1970-01-01
      • 2022-11-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多