You need to sign in to do that
Don't have an account?
FeedComment Test Class Missing FeedItemId
Hi All,
We created a trigger on FeedComment - a new record under ChatterPost will be created automatically when a comment contains keyword "legal". The test class has error that missing FeedItemId, we're not sure how to get it fix, please help.
Error Message System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [FeedItemId]: [FeedItemId]
Stack Trace Class.CommentKeywordlegalTest.insertNewChatterPostTest: line 13, column 1
@isTest
public class CommentKeywordlegalTest
{
static testMethod void insertNewChatterPostTest()
{
Test.StartTest();
FeedItem f = new FeedItem();
f.ParentId = UserInfo.getUserId();
f.body = 'test';
insert f;
FeedComment fc = new FeedComment();
fc.CommentBody = 'legal test';
insert fc;
Test.StopTest();
System.assertEquals ('legal test', fc.commentbody);
}
}
TRIGGER:
Trigger CommentKeywordLegal on FeedComment (after insert) {
List<FeedComment> FeedComments = new List<FeedComment>();
for (FeedComment f : Trigger.new) {
if (f.commentbody!=null && f.commentbody.contains('legal' ) ) {
ChatterPost__c C = new ChatterPost__c();
c.Description__c = f.commentbody;
insert C;
}
}
}
We created a trigger on FeedComment - a new record under ChatterPost will be created automatically when a comment contains keyword "legal". The test class has error that missing FeedItemId, we're not sure how to get it fix, please help.
Error Message System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [FeedItemId]: [FeedItemId]
Stack Trace Class.CommentKeywordlegalTest.insertNewChatterPostTest: line 13, column 1
@isTest
public class CommentKeywordlegalTest
{
static testMethod void insertNewChatterPostTest()
{
Test.StartTest();
FeedItem f = new FeedItem();
f.ParentId = UserInfo.getUserId();
f.body = 'test';
insert f;
FeedComment fc = new FeedComment();
fc.CommentBody = 'legal test';
insert fc;
Test.StopTest();
System.assertEquals ('legal test', fc.commentbody);
}
}
TRIGGER:
Trigger CommentKeywordLegal on FeedComment (after insert) {
List<FeedComment> FeedComments = new List<FeedComment>();
for (FeedComment f : Trigger.new) {
if (f.commentbody!=null && f.commentbody.contains('legal' ) ) {
ChatterPost__c C = new ChatterPost__c();
c.Description__c = f.commentbody;
insert C;
}
}
}
I'm Shingo Yamazaki.
It's probably because you forgot to set "feedItemId" on FeedComment.
Does it work?
All Answers
I'm Shingo Yamazaki.
It's probably because you forgot to set "feedItemId" on FeedComment.
Does it work?