You need to sign in to do that
Don't have an account?
runnerbray
Add Attachment to Chatter Feed
I need to add account attachments to the chatter feed automatically. I have the following code which adds all attachments to the chatter feed, not just Account object attachments. How can I make it specific to the account object? Or make it specific to a file name?
trigger AttachFileToAccountFeed on Attachment (before insert) { ID accountId; list<FeedItem> listOfFeedFiles = new List<FeedItem>(); if(Trigger.isBefore){ for(Attachment attachment : trigger.new){ string checkIfCase = 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; } }
You can do the following as I did on line 9 below.
The Attachment's Name will be the name of the file, so if you want to check for a specific filename just do this:
Hope that helps,
Clint
All Answers
You can do the following as I did on line 9 below.
The Attachment's Name will be the name of the file, so if you want to check for a specific filename just do this:
Hope that helps,
Clint
Code Coverage Failure
The following triggers have 0% code coverage. Each trigger must have at least 1% code coverage. AttachFileToAccountFeed
This is the first trigger I've ever attempted. What do I need to do to resolve the code coverage error?
Hope that helps,
Clint
I tried your code, but i'm facing this issue.
'Invalid field ContentFileName for SObject FeedItem'
Can you help me on this,
Thanks in advance