You need to sign in to do that
Don't have an account?
umakanth mettu
chatter trigger Help on Test class
Hi All,
we want to activate the chatter for email to case in lightning but we do not want any person to post or comment using chatter.
I have written two triggers for not posting anything and also commenting via case feed both are working fine but failed to write a test classes for both.
FeedItem:
trigger ChatterCommentItem on FeedItem (before insert) {
for(FeedItem fi : trigger.new)
if(fi.type == 'ContentPost' || fi.type == 'TextPost')
fi.addError('you do not have permissions to post any comment or File.Please contact your system administrator.');
}
FeedComment
trigger ChatterComment on FeedComment (Before Insert) {
for(FeedComment fc : trigger.new)
if(fc.CommentType == 'ContentComment' || fc.CommentType == 'TextComment' )
fc.addError('you do not have permissions to post any comment or File.Please contact your system administrator.');
}
I have written feed comment trigger for case object when the case status or any changes happens case feed is generated so no one should comment on it any help on the test classes for both triggers would be appriciated thank you.
we want to activate the chatter for email to case in lightning but we do not want any person to post or comment using chatter.
I have written two triggers for not posting anything and also commenting via case feed both are working fine but failed to write a test classes for both.
FeedItem:
trigger ChatterCommentItem on FeedItem (before insert) {
for(FeedItem fi : trigger.new)
if(fi.type == 'ContentPost' || fi.type == 'TextPost')
fi.addError('you do not have permissions to post any comment or File.Please contact your system administrator.');
}
FeedComment
trigger ChatterComment on FeedComment (Before Insert) {
for(FeedComment fc : trigger.new)
if(fc.CommentType == 'ContentComment' || fc.CommentType == 'TextComment' )
fc.addError('you do not have permissions to post any comment or File.Please contact your system administrator.');
}
I have written feed comment trigger for case object when the case status or any changes happens case feed is generated so no one should comment on it any help on the test classes for both triggers would be appriciated thank you.
Please check test classes;-
For FeedItem:-
@isTest
private class ChatterCommentItemtest {
@isTest
static void testBeforeInsert() {
FeedItem fi = new FeedItem();
fi.name = 'fi';
fi.ParentId = UserInfo.getUserId();
fi.type = 'ContentPost';
Test.startTest();
Database.SaveResult result = Database.insert(fi, false);
Test.stopTest();
System.assertNotEquals(null, result.getErrors()[0].getMessage(), 'error message');
}
}
For FeedComment;-
@isTest
private class ChatterCommentFeedCommenttest {
@isTest
static void testBeforeInsert() {
FeedComment fc = new FeedComment();
fc.name = 'fc';
fc.CommentType = 'ContentComment';
Test.startTest();
Database.SaveResult result = Database.insert(fc, false);
Test.stopTest();
System.assertNotEquals(null, result.getErrors()[0].getMessage(), 'error message');
}
}