You need to sign in to do that
Don't have an account?

Insert a copy of Attachment into a Chatter Feed as a File for Sharing on custom object
Hi,
I need to add 'custom object' attachments to the chatter feed automatically. I have the following code but i'm facing some issues
trigger AttachFileToCustomFeed on Attachment (after insert) {
ID customId;
list<FeedItem> listOfFeedFiles = new List<FeedItem>();
if(Trigger.isAfter){
for(Attachment attachment : trigger.new){
string checkIfCase = string.valueof(attachment.Description); {
customId= attachment.ParentId;
FeedItem post = new FeedItem();
post.ParentId = customId;
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;
}
}
but i'm gettiing the below error
'Invalid field ContentData for SObject FeedItem'
If I comment the 'ContentData' then i'm getting this
'Invalid field ContentFileName for SObject FeedItem'.
Can anyone please help in this issue.
Thanks in advance.
I need to add 'custom object' attachments to the chatter feed automatically. I have the following code but i'm facing some issues
trigger AttachFileToCustomFeed on Attachment (after insert) {
ID customId;
list<FeedItem> listOfFeedFiles = new List<FeedItem>();
if(Trigger.isAfter){
for(Attachment attachment : trigger.new){
string checkIfCase = string.valueof(attachment.Description); {
customId= attachment.ParentId;
FeedItem post = new FeedItem();
post.ParentId = customId;
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;
}
}
but i'm gettiing the below error
'Invalid field ContentData for SObject FeedItem'
If I comment the 'ContentData' then i'm getting this
'Invalid field ContentFileName for SObject FeedItem'.
Can anyone please help in this issue.
Thanks in advance.
If anyone facing the same issue, please change the version for the trigger then it will work