You need to sign in to do that
Don't have an account?
Vader
Need Help with Test Class for Chatter Feed Insert
I have a trigger that will insert a feed item whenever an attachment is added to a record. I've tried a few things to get a test class in place but am striking out. Here is the trigger:
trigger attachmentTrigger on Attachment (after delete, after insert, after update) { if(trigger.isinsert) { for(Attachment a:trigger.new){ //system.debug(a); feedItem f= new feedItem(); f.ParentId=a.ParentId; f.Title=a.Name; //f.body=a.body; f.body=((Trigger.isInsert) ? 'New' : 'Updated') +'Attachment'+ ' '+ a.Name +' ' +'is added '; insert f; //system.debug('f.id--->'+f.id); } } if(trigger.isdelete) { for(Attachment a:trigger.old){ //system.debug(a); feedItem f= new feedItem(); f.ParentId=a.ParentId; f.Title=a.Name; //f.body=a.body; f.body=((Trigger.isDelete) ? 'Attachment' : 'Deleted') + ' '+ a.Name +' ' +'is deleted '; insert f; //system.debug('f.id--->'+f.id); } } }
Any help writing a test class would be hugely appreciated!
All Answers
Try this
@isTest
private class testClass_Trigger{
private static TestMethod void JWGetAssociations(){
Account acct1 = new Account(name='TestAccount1');
insert acct1;
Attachment a = new Attachment();
a.ParentId = acct1.id;
a.name = 'Test';
insert a;
delete a;
}
}
If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.
Thanks
Thanks for the help! I got the following error:
System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Body]: [Body]
I added 'a.Body' and set a text value it to meet the required field request and got the following error:
Description Resource Path Location Type
Save error: Illegal assignment from String to Blob
Not sure how to load a body type of blob so that it will be recognized in the test class.
Fantastic! Worked great. Thanks to the both of you for helping. Kudos given!