You need to sign in to do that
Don't have an account?
rashi krishan
How to write code for try catch in test class for the following code
Hi,
Please let me how to write code in test class for try catch for the following code
try{
List <Lead> LeadsToUpdate = [Select Id from Lead where Id IN :Leadids AND isconverted = false FOR UPDATE];
If(!LeadsToUpdate.isEmpty())
Update LeadsToUpdate;
}
catch(System.DmlException e){
for (Integer i = 0; i < e.getNumDml(); i++) {
if(e.getDmlType(i) == StatusCode.FIELD_CUSTOM_VALIDATION_EXCEPTION){
Trigger.new[i].addError(e.getDmlMessage(i));
}
}
}
Catch(Exception e){
for (Integer i = 0; i < e.getNumDml(); i++) {
if(e.getDmlType(i) == StatusCode.FIELD_CUSTOM_VALIDATION_EXCEPTION){
Trigger.old[i].addError(e.getDmlMessage(i));
}
}
}
Please revert ASAP
Please let me how to write code in test class for try catch for the following code
try{
List <Lead> LeadsToUpdate = [Select Id from Lead where Id IN :Leadids AND isconverted = false FOR UPDATE];
If(!LeadsToUpdate.isEmpty())
Update LeadsToUpdate;
}
catch(System.DmlException e){
for (Integer i = 0; i < e.getNumDml(); i++) {
if(e.getDmlType(i) == StatusCode.FIELD_CUSTOM_VALIDATION_EXCEPTION){
Trigger.new[i].addError(e.getDmlMessage(i));
}
}
}
Catch(Exception e){
for (Integer i = 0; i < e.getNumDml(); i++) {
if(e.getDmlType(i) == StatusCode.FIELD_CUSTOM_VALIDATION_EXCEPTION){
Trigger.old[i].addError(e.getDmlMessage(i));
}
}
}
Please revert ASAP
MagulanDuraipandian
Check this sample - http://www.infallibletechie.com/2015/11/test-class-to-cover-catch-block-in.html