2

Whenever an image is posted in record chatter feed post, i want to save that image into attachment. How can i get the image from record feedpost.

trigger FeedToattach on FeedItem (after insert) {
    system.debug('^^^'+trigger.new[0].Id);
    List<Attachment> lstToAttach = new List<Attachment>();
    ContentDocumentFeed objDoc = [Select Id,ParentId from  ContentDocumentFeed order by createdDate Desc limit 1];
    system.debug(objDoc.ParentId);
    for(FeedItem objFI : Trigger.New){ 
        Attachment objAttach = new Attachment(); 
        objAttach.Body = objFI.ContentData; }
    }

}

2

The file is available in Content Version object in salesforce.

You can trigger on the feed post. Write an after insert trigger on feed post to copy the file to attachment

| improve this answer | |
  • I have tried the trigger but don't know how to get the attached image. Am getting the error as "Invalid field ContentData for SObject FeedItem". for(FeedItem objFI : Trigger.New){ Attachment objAttach = new Attachment(); objAttach.Body = objFI.ContentData; } – Shashi Reddy Jun 27 '16 at 12:27
  • 1
    Can you post the code so we look what have you tried? – Mohith Shrivastava Jun 27 '16 at 12:28
  • Please find the code in the post – Shashi Reddy Jun 28 '16 at 7:53
  • @Shashi Your trigger shouldb be on content document and not feed item – Mohith Shrivastava Jun 29 '16 at 1:22
  • which field i can use to get the Body from the image to add in attachment. – Shashi Reddy Jun 29 '16 at 9:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.