+ Start a Discussion
James HayesJames Hayes 

Visualforce - Fields are getting wiped after validation rule triggers for a format error per page refresh

We have a pretty lengthy visualforce page where consultants fill out their account plan. Quite a few fields are of type number -- also date, which is less problematic. If the user fills out 40 fields and happened to enter something other than a number into the corresponding number field, all 40 fields get wiped when they click save due to the refresh. I am looking for some alternatives here. I am using the Database.upsert() with the allornone parameter as false, but that functionality seems to be undefined, with little documentation found online. Also, we do not want to change the number fields to free form text, due to the fact that reporting would be difficult/impossible. I was thinking about using javascript to verify the format of the input. Any suggestions? Input would be appreciated.

Save Method Below
public PageReference saveOverride() {
    plan.Opportunity_Name__c = oppId; 
    //upsert plan; 
    Database.upsert(plan, false); 

    for(Integer i = 0; i < ADQR_records.size(); i++) {
        ADQR_records.get(i).Account_Plan__c = plan.Id;
    upsert ADQR_records;

    for(Integer i = 0; i < Persona_records.size(); i++) {
        Persona_records.get(i).Account_Plan__c = plan.Id;
    upsert Persona_records; 

    for(Integer i = 0; i < Carrier_records.size(); i++) {
        Carrier_records.get(i).Account_Plan__c = plan.Id;
    upsert Carrier_records; 

    for(Integer i = 0; i < Theme_records.size(); i++) {
        Theme_records.get(i).Account_Plan__c = plan.Id; 
    upsert Theme_records; 

    PageReference previous = new PageReference('/apex/Account_Plan_Page?value=' + oppId);
    return previous;

Raj VakatiRaj Vakati
Hi James, 
Try to do as shown below. If Any errors didn't do any redirects and show the errors with page messages else do the redirects 
updaet plan ; 

}catch(Exception e){
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Please enter value'));
    return null;
Insert the below tag inside the visualforce page within page block
<apex:pageMessages ></apex:pageMessages>