You need to sign in to do that
Don't have an account?
Connor Cain
Case Comment Test Class for Update
I can't get a test class to work for a Trigger that is only looking for when a Case Comment is Updated.
trigger validation on CaseComment (before update) {
if(Trigger.isUpdate){
for(CaseComment caseCmt : Trigger.new){
if(caseCmt.CreatedById != System.UserInfo.getUserId()){
caseCmt.addError('You can not edit Someone else\'s Comment');
}
}
}
}
Any Help/Advice would be appreciated:)
trigger validation on CaseComment (before update) {
if(Trigger.isUpdate){
for(CaseComment caseCmt : Trigger.new){
if(caseCmt.CreatedById != System.UserInfo.getUserId()){
caseCmt.addError('You can not edit Someone else\'s Comment');
}
}
}
}
Any Help/Advice would be appreciated:)
All Answers
public class ValidationTest {
Static testMethod void TriggerTest(){
CaseComment cc = new CaseComment();
cc.CommentBody = 'cc test';
update
}
}
this is what i had so far, I also was working on creating a Case but lost the code.
- Create a Case
- Create a CaseComment with its ParentId set to your Case Id.
- Create a test User. In order to prevent email messages being delivered where they shouldn't go, use @example.com as the email domain for any test User or Contact.
- Use System.runAs(testUser){} to create a code block to be executed as your test User.
- Attempt to update the CaseComment record you created earlier.
Let us know how you fare.Update the code as like below for safe side to handler the exception also