You need to sign in to do that
Don't have an account?
Rajnisf
test class to cover .adderror...need help...urgent
for(Task a : Trigger.old){
if(a.OwnerId != UserInfo.getUserId() && ProfileId != '00e00000006qrDIAAY' )
{
a.addError('You are not authorised to delete this task!');
}
}
}
In your test code,
1. query a user who does not have this Id and ProfileId.
2. use system.runAs to run that code through his login.
// CODE HERE //
@isTest
private static void testingTaskDelete(){
Task t = new Task();
// give all required fields
insert t;
User someOtherUser = [Select Id From User Where Id != UserInfo.getUserId() AND ProfileId != '00e00000006qrDIAAY' And isActive = TRUE LIMIT 1];
system.runAs(someOtherUser){
delete t;
}
}
All Answers
Create a test record in a such way that it should call an error. Put the DML operation inside try/catch black. By doing this test methods wont go fail and you can cover error message.
Hops this helps :)
Thanks,
Devendra
Can you please paste your trigger and test method code here?
Thanks,
Devendra
In your test code,
1. query a user who does not have this Id and ProfileId.
2. use system.runAs to run that code through his login.
// CODE HERE //
@isTest
private static void testingTaskDelete(){
Task t = new Task();
// give all required fields
insert t;
User someOtherUser = [Select Id From User Where Id != UserInfo.getUserId() AND ProfileId != '00e00000006qrDIAAY' And isActive = TRUE LIMIT 1];
system.runAs(someOtherUser){
delete t;
}
}
thanx a lot....
it is covered now....100 %