I am inserting some new records using the apex class. I wrote some error conditions; if the error condition matches it will return null and show the error message on the VF page for which the record failed.
But I want to show all errors at once instead of showing the only error where it stopped.
Is it possible?
Class:
List<StandardProduct__c> spList = new List<StandardProduct__c>();
for(Integer i=1;i<list.size();i++){
val = list[i].split(',');
StandardProduct__c sp = new StandardProduct__c();
sp.xyProd_c = val[0];
sp.xyqty_c = val[1];
sp.xyPrice= val[2];
if(sp.xyProd_c != 'Test'){ // If one record enters this condition it is stopping here and just showing only error for one record
error.add('Invalid prod' + sp.xyProd_c);
return null;
}
if(sp.xyqty_c != null && sp.xyPrice != null)
{
spList.add(sp);
}
else if(some condition){ // The same as the first condition, showing only one error which entered here
error.add('Failed to upload' + sp.xyProd_c);
return null;
}
}
return
after finding the error that will allow your code to continue executing after the first error is found, if you don't want code to fire after one error is found you can use check that error map is empty (e.g.if(error.isEmpty) { // do something }