2015-09-10 2 views
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; 
} 

}

ответ

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

} 

 Смежные вопросы

  • Нет связанных вопросов^_^