I've got a Visualforce Page that is just a form with a Save button.
I'm trying to display a message if the record is inserted correctly or not, and if it is inserted correctly I want to reload the page and delete every value stored in the form.
I have this Apex Code:
public PageReference save() {
try {
upsert accRecord;
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM,'Record submited successfully'));
} catch(System.DMLException e) {
//ApexPages.addMessages(e);
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please enter Account Name'));
return null;
}
// After successful Save, navigate to the default view page
PageReference tempPage = ApexPages.currentPage();
tempPage.setRedirect(true);
return tempPage;
//return null;
}
Right now it doesn't show the message, but if I delete the PageReference tempPage variable and leave return null
it will show the message and but stay in the same page with the values of the inserted record.