You need to sign in to do that
Don't have an account?
AlphaP
Test Error Method
I have 90% test class coverage for a trigger with the exception of this one line in my code:
27 | else if ((tmpDNCList.size()<1) && (myLead.Sub_Status_ALL__c == 'DNC Requested')) |
28 | { |
29 | Trigger.new[0].Status.addError('Please add DNC record to Salesforce prior to saving.'); |
When I create a record in the test class that matches this critieria - it causes a DML exception (as it should) and halts all of my other tests if I run them all at once and it drops my code coverage to almost 50%. The class itself gets 100% coverage though.
Is there something sepcial about wiritng a test class when using the error method?
in your test code,
put the dml in a try catch block catching dml exceptions....
Try{
insert xxx;
}catch (dmlException e){
system.assertEquals(True,e.getDMLMessage(0).contains('Please add DNC record to Salesforce prior to saving.'));
}
All Answers
in your test code,
put the dml in a try catch block catching dml exceptions....
Try{
insert xxx;
}catch (dmlException e){
system.assertEquals(True,e.getDMLMessage(0).contains('Please add DNC record to Salesforce prior to saving.'));
}
Thanks - I didn't even know what to search in the dev guides. Exactly what I needed.