function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
tdevmantdevman 

reproduce exception to cover negative test

Noam.dganiNoam.dgani

Hi

 

i'm assuming that the code is called from a trigger of an INSERT on contact, right?

and that there is more to your test method than you published?

 

basically, the easiest way that i see to throw your exception would be to insert the Contact with null value in mailingPostalCode.

this line:

String mailingPostalCode= String.valueOf(c.mailingPostalCode);

would throw an exception that the argument of "String.valueOf()" cannot be null.

 

BUT, you might want to handle that better (with no relation to the test coverage).

 

Additionally,

in this query - 

Map<Id, Account> aMap = new Map<Id, Account>([SELECT Id, channel__c, status__c FROM Account WHERE id =: aSet AND (Status__c = : 'Active' OR Status__c =: 'Partner' )]);

 

you do id=: aSet

 

didnt you mean

id IN: aSet

 

?