I want to write a trigger to insert a feed in chatter which could be a link to the library when I create a content in a library.{ Link to the content in the library preferably .But even a link to the library will do}
trigger ContentVersionTrigger on ContentVersion (after insert)
{
ContentVersion[] cv=Trigger.new;
InsertToChatter.InsertContent(cv);
}
public class InsertToChatter
{
public static void Insertcontent (ContentVersion[] cv)
{
FeedItem post = new FeedItem(); post.Body = 'New file has been created.Pls check link';
post.LinkUrl= URL('cs18.salesforce.com/sfc/#version?selectedDocumentId='+ cv.ContentDocumentId' ;
insert post;
}
}
Attribution to: sahitya
Possible Suggestion/Solution #1
You can do this by creating a trigger on ContentDocument SObject on after insert event to get the Id of the document and create a FeedItem record with a link to your ContentDocument (/sfc/#version?selectedDocumentId=yourDocumentId)
Give it a try and post your code here if you need help with it
Attribution to: melmoussaoui
Possible Suggestion/Solution #2
I have tried writting trigger on ContentDocument. It is working as of now..
Here it is the code :-
trigger PublishlinkOnChatter on ContentDocument (After insert,After Update) {
list<FeedItem> lst=new List<feedItem>();
for(ContentDocument cd:trigger.new){
FeedItem fi= new FeedItem();
fi.LinkUrl='https://na15.salesforce.com/'+cd.LatestPublishedVersionId;
fi.parentid=userinfo.getUserID();
fi.body='Modified the Content';
lst.add(fi);
}
insert lst;
}
Attribution to: AnkushSalesforce
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/33665