You need to sign in to do that
Don't have an account?
MIKE_DAY
Trigger to insert Chatter File on a Task to the Attachment Related List
Hi Guys,
I have started using Chatter for Mobile and, in many cases, this allows me to attach images to records and have them appear as attachements against the record. This is not supported however when uploading Chatter files to Tasks as the image will stay in the chatter feed but not the Attachment Related List.
Does anyone have an example of a trigger that will take a Task's Chatter feed (files only) when created and insert it as a Task Attachment?
If not, could you point me in the right direction please?
Many thanks
Mike
I have a solution that works for me.
trigger Feedattachment on FeedItem (after insert) {
try { // Start of Try
List<Attachment> Att = new List<Attachment>();
for (FeedItem f : trigger.new)
{ // Start of For Loop
string what = f.ParentId;
if((what.startsWith('00T')) && (f.Type == 'ContentPost')){
try {
System.debug('triggerfire');
Att.add(new Attachment(
ParentId = f.ParentId,
Name = f.ContentFileName + ' ' + System.now(),
body = f.ContentData
));
} catch (Exception e) { }
} // End If
} // End Loop
insert Att;
} // end try
catch (Exception e) {
} // end catch
} // End Trigger
All Answers
I have a solution that works for me.
trigger Feedattachment on FeedItem (after insert) {
try { // Start of Try
List<Attachment> Att = new List<Attachment>();
for (FeedItem f : trigger.new)
{ // Start of For Loop
string what = f.ParentId;
if((what.startsWith('00T')) && (f.Type == 'ContentPost')){
try {
System.debug('triggerfire');
Att.add(new Attachment(
ParentId = f.ParentId,
Name = f.ContentFileName + ' ' + System.now(),
body = f.ContentData
));
} catch (Exception e) { }
} // End If
} // End Loop
insert Att;
} // end try
catch (Exception e) {
} // end catch
} // End Trigger