+ Start a Discussion
NUBESNUBES 

custom save does not show validation messages

Hi, 

 

I have built a visualforce page and when using the standard SAVE commandbutton it will show the validation messages on the page, however when using an extension it does not show the validation messages. The reason I am using an extension is because I want to re-direct to another visualforce page.

  

Could someone look at the below code and let me know if I have missed a command that shows the validations

 

 

public PageReference Submit() { insert wreq; PageReference myPage = new PageReference('/apex/engagement_request_review?id=' + wreq.id); myPage.setRedirect(true); return myPage; }

 

 

 

bob_buzzardbob_buzzard

When you say that it doesn't show the validation messages, does this mean that you return to the same page but with no indication of error, or that your redirect works?

 

Can you show us the VF page, and also tell us a bit more about the validation messages?  E.g. are these for required fields on the page, required fields on the object, validation rules? 

BeeddiskShahBeeddiskShah
Use try catch block to catch DML exception and return null in catch.  
  public PageReference Submit() { 
try{ 
     insert wreq;      
PageReference myPage = new        PageReference('/apex/engagement_request_review?id=' + wreq.id);      myPage.setRedirect(true);      return myPage;   }

}catch (exception){
return null; 
}