+ Start a Discussion
Skip KSkip K 

Field.addError not working

I'm having trouble getting field.addError to work the way I think it should. I'm using the following to try and add an error to an opportunity field. It makes it through the the addError part, but nothing happens on my VF page.

public void saveOpportunity() {
//OpportunityWrapper is an inner class containg an Opportunity
  for (OpportunityWrapper oWrapper : opportunityList) {
   System.debug('--------------------');
   if (oWrapper.opp.Id == saveOppId) { //SaveOppId is passed from the VF page
    try {
     Database.SaveResult oppUpdateResult = Database.update(oWrapper.opp, false);
     String errorMessage = '';
     if(oppUpdateResult.isSuccess()) {
      saveButtonDisabledMap.put(saveOppId, true);
     } else if(!oppUpdateResult.isSuccess()) {
      saveButtonDisabledMap.put(saveOppId, false);
     
      for (Database.Error error : oppUpdateResult.getErrors()) {
       //Database.Error error = oliUpdateResults.get(i).getErrors().get(0);
       for (String s : error.getFields()) {
        System.debug('Status__c error: '+error.getMessage());
        if (s == 'Status__c') {
         System.debug('before STATUS ADDERROR');
         oWrapper.o.Status__c.addError(error.getMessage());
         System.debug('after STATUS ADDERROR');
        }
       }
      }
     }
    } catch(Exception e) {
     system.debug('Bad exception: ' + e.getMessage());   
    }
   }
  }
}


Andy BoettcherAndy Boettcher
Do you have the VF messages component on your page that is in an area that rerenders on the commandbutton press?
Skip KSkip K
Thanks techman97 - It was working, I just didn't rerender the the right Id.