• Ravali Putta 1
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
Hi,
My requirement is whenever file or note attched to a record I have post(upload) that file in chatter group. I have written a trigger on Attachment object ,It is working. And also written on ContentDocument object, this is also not firing. I don't know much about ContentDocument object. I have searched for this but I do not get proper solution.

Any helpwould be greatly appreciated....many thanks,

My trigger - same on Attchment and ContentDocument

trigger postattachment on ContentDocument (after insert) {

    Deal_Support_Request__c[] d = [select Name from Deal_Support_Request__c limit 1];
    String obj;
    System.debug('yessssssssssss'+obj);
       if(d.size()>0)
    {
        obj = d[0].id;
        obj=obj.substring(0,2);
        System.debug('');
    }
    for(ContentDocument att: Trigger.New)
        {    String parentObjId = att.ParentId;
         system.debug('------------entered for---------');
            if(parentObjId.startsWith(obj))
            {
                system.debug('------------entered if---------');
                FeedItem post = new FeedItem();
                post.ParentId = att.ParentId; //eg. Opportunity id, custom object id..
                post.Body = 'Attachment added';
                insert post;
                System.debug('post-------->'+post);
                FeedAttachment fatt = new FeedAttachment();
                fatt.FeedEntityId = post.id;
                fatt.RecordId = att.id;
                fatt.Title=att.Title;
                fatt.Type='Content';
               
insert fatt;
              
                
               
            }
        }

}