1

I have a custom page. When I on click save button it does not save anything. Is there anything wrong with my code that I could not find? Thanks

 public PageReference save() {
        if(controller.save() != null) {
        PageReference congratsPage = Page.pitu3;
        congratsPage.setRedirect(true);
        congratsPage.getParameters().put('id',controller.getId());
        return congratsPage;
        }return null;
    }
  • 2
    Assuming controller is the StandardController, one reason might be that there is a data validation error on the save. Make sure you have an apex:messages in your Visualforce to see the error output. This is only relevant to the controller.save() returning null path. – Keith C Jul 2 '15 at 15:03
0

There must be some validation or system error as suggested by Keith. I would suggest to use below to show error to user or at at least use system.debug to see what is going on.

Try{
      if(controller.save() != null) {
           PageReference congratsPage = Page.pitu3;
           congratsPage.setRedirect(true);
           congratsPage.getParameters().put('id',controller.getId());
           return congratsPage;
          }return null;
Catch(Exception e){
   ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR, e.getMessage());
   ApexPages.addMessages(myMsg);
   return null;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.