function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
deepu.sandeepdeepu.sandeep 

Validation Rules

 I am getting validation error like ths after clicking submit button.

 

Visualforce Error


System.DmlException: Upsert failed. First exception on row 0 with id a0090000002qLz4AAE; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Start Date must be less than End Date: [StartDate__c]
Class.input1.save: line 36, column 1

 

i want error messages near the field in vf page what i have to do for dat.

Navatar_DbSupNavatar_DbSup

Hi,

 

In apex class where you are inserting or updating  the record put the code in try catch block. In catch block catch the exception and assign the error message to a class property after that display the error message below the field by using apex:outputlabel.

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

 

deepu.sandeepdeepu.sandeep

I tried this but its not working see this code and if any mod's please tell me

wat to do

 

public class input1 {
 public Endeavor_Reg_Form__c e{get; set;}
 public list<Endeavor_Reg_Form__c> con{get;set;}
 
  public input1()
  {
    
    id id1 =  ApexPages.currentpage().getParameters().get('id');  
    if(id1<>null)
     {  
       e=[select id,name,city__c,Annual_budget_in_your_control_in_usd__c,Cell_Phone__c,College_University__c,College_University1__c,College_University2__c,Company__c,
            Company_Organization__c,Company_Organization1__c,Company_Organization2__c,Company_Organization3__c,Country__c,Country_of_Citizenship__c,Date_of_Birth__c,Degree_Granted__c,Degree_Granted1__c,Degree_Granted2__c,
            Email__c,Emergency_Contact_Name__c,Emergency_Contact_Phone__c,Emergency_Contact_Relationship__c,End_Date__c,End_Date1__c,End_Date2__c,End_Date3__c,
            Gender__c,Home_Address__c,Home_Address_Line_2__c,Home_Phone__c,Industry__c,Job_Title_at_Current_Employer_if_applic__c,
            Job_title_of_person_to_whom_you_report__c,Last_Family_Name__c,List_of_Language_s_in_which_you_are_flu__c,
            Major__c,Major1__c,Major2__c,Middle_Initial__c,Name_for_Identification_Badge__c,Number_of_people_you_manage_directly__c,
            Objectives__c,Position__c,Position1__c,Position2__c,Position3__c,Responsibilities__c,Salutation__c,StartDate__c,StartDate1__c,StartDate2__c,StartDate3__c,Start_Date__c,State_Province_non_US__c,
            State_US__c,Year_Granted__c,Year_Granted1__c,Year_Granted2__c,Zip_Postal_Code__c from Endeavor_Reg_Form__c where id=:id1];
    
     }
    else
     {   
       e = new Endeavor_Reg_Form__c();    
     }
  }

 public pagereference save()
  {
     try
      {
        update e;
      }
     catch(DmlException ex){
        ApexPages.addMessages(ex);
      }
    upsert e;
    return new Apexpages.standardcontroller(e).view();

  }
 public pagereference edit()
  {
   update e;
   return new Apexpages.standardcontroller(e).edit();
  }
 
}

SeAlVaSeAlVa

May I ask the reason for this?

 try
 {
     update e;
 }catch(DmlException ex){
     ApexPages.addMessages(ex);
 }
 upsert e;

 That code tries to update e. Either if it goes fine or fails, it performs and upsert over e again.

 

consider doing the following change

try{
    update e;
}catch(DmlException ex){
    ApexPages.addMessages(ex);
}catch(Exception e){
    try{
        upsert e;
    }catch(DmlException ex){
        ApexPages.addMessages(ex);
    }
}

 

I also recommend to add a Generic catch statement "catch (Exception e) {}" just in case, so after you perform all your tests, add it to the second 'try' statement.

 

Regards.