I have two different approaches for adding an error to my visualforce page. The first approach I am concatenating a string at the end of exception. The second approach I am simply returning the message from the Exception itself.
However I'm not sure why the first one would display a duplicate and redudant error message. I want to use the first approach (with the record name at the end)... but I don't want the duplicate message in the beginning.
public PageReference saveChanges(){
problematicIds = new Set<Id>();
try{
update InterBUoppz;
}
catch(DmlException de) {
Integer numErrors = de.getNumDml();
for(Integer i=0;i<numErrors;i++) {
//Image 1: this gives a duplicate message on top (only for the first error)
//ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, de.getDmlMessage(i)+' - Opportunity: '+oppListMap.get(de.getDmlId(i)).Name));
//Image 2: this works fine but it is not as precise
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, de.getDmlMessage(i)));
}
errorsFound = true;
}
return null;
}
addMessage
twice when you observe the behavior in the first image?