Trigger On ContentDocument object Salesforce!
Hi guys!
These days am practicing out Triggers . In-fact I must say it is one of the best exercise to build your logic and get familiar with how coding is done in salesforce.
So, Lemme First explain you the scenario.:-
Say You want to write a trigger to insert a feed in chatter which could be a link to the library when I create a content or edit it anything in a library..
it says If when ever you add or edit any file in library then its link should be posted as link on chatter.
Its very simple one should be familiar with contentDocument object as this object is not available in salesforce UI. But it is available on background of salesforce.
So you must be thinking then how do I got to know about this one . Well, Keep exploring. Anyways . I got to know about this one through Developer console. Also from there you can create the trigger.
Here , is the simple code For you ...
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;
}
happy Coding!!!
Cheers!!!
ankushsalesforce@gmail.com
Cheers!!!
ankushsalesforce@gmail.com
No comments:
Post a Comment