Find your content:

Search form

You are here

How to Save a record With out ValidationRule Fields on VF Page


I created a VF page With some inputfield components these fields don't have any validation rules but when i am trying to save the records after entering the details in it. I am getting an error MSG as

Insert failed. The first exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, You must review the preferences section before you can save this record.

There are some validation rules on other fields in the same object. According to my requirement I don't want validation fields on my VF page now.

    <apex:page controller="controllerclass">
        .headerRow th{
          <apex:stylesheet value="/sCSS/21.0/sprites/1297816277000/Theme3/default/gc/versioning.css" />
              <apex:tabPanel switchType="client" selectedTab="opportunities2" id="theTabPanel"  >
                  <apex:tab label="tab1" id="Tabone" style="font-weight:bold;width:200px;">
                      <apex:pageblock title="New Lead">
                          <apex:pageblocksection >
                              <apex:form >
                              <apex:commandLink action="{!records}" immediate="true">
                                  <apex:image value="{!$Resource.Logo_Medium}" height="100" width="100" />
                              <apex:commandLink action="{!action}" immediate="true">
                                  <apex:image value="{!$Resource.Logo_Transparent}" height="50" width="200" />
                  <apex:tab label="tab2" id="TabTWO" style="font-weight:bold;width:200px;" name="opportunities2">
                      <apex:form >
                          <apex:pageblock title="Opportunities" mode="edit" >
                              <apex:pageBlockButtons >
                                  <apex:commandButton value="Save" action="{!dosave}" style="Margin-left:250px" immediate="true"/>
                              <apex:pageblocksection >
                                  <apex:pageBlockTable value="{!Opportunities}" var="Opportunity" > 
                                      <apex:column headerValue="RecordTypeId" value="{!Opportunity.RecordTypeId}" />
                                      <apex:column headerValue="Name" value="{!}" />
                                      <apex:column headerValue="StageName" value="{!Opportunity.StageName}"/>
                                      <apex:column headerValue="CloseDate" value="{!Opportunity.CloseDate}"/>
                                      <apex:column headerValue="Sales Representative" value="{!Opportunity.Sales_Rep__c}"/>
                                      <apex:column headerValue="Date Of Appointment" value="{!Opportunity.Date_of_Appointment__c}"/>
                              <apex:pageBlockSection title="Information" columns="2" >
                                  <apex:inputField label="Start" value="{!event.StartDateTime}" />
                                      <apex:selectList label="Sales Consultant" size="1" value="{!Consultantname}" >
                                          <apex:selectOptions value="{!ActiveSalesConsultant}" ></apex:selectOptions>
                                  <apex:inputField label="deal with" value="{!lead.LastName}" />&nbsp;
                                  <apex:inputField label="Duration" value="{!event.DurationInMinutes}"/>&nbsp;
                              <apex:pageBlockSection title="Opportunity Information" columns="2">
                                  <apex:inputField value="{!}"/>
                                  <apex:inputField value="{!ObjOpportunity.StageName}"/>
                                  <apex:inputField value="{!ObjOpportunity.AccountId}"/>
                                  <apex:inputField value="{!ObjOpportunity.CloseDate}"/>

Attribution to: rakesh

Possible Suggestion/Solution #1

Add the property immediate="true" to your command button.

<apex:commandButton value="Save" immediate="true" action="{!save}"/>

Edited: Refer the link here

Attribution to: Priyanka

Possible Suggestion/Solution #2

You can't turn off validation rules from a Visualforce page, as per the order of execution from the apex docs:

On the server, Salesforce:

.1. Loads the original record from the database or initializes the record for an upsert statement. .2. Loads the new record field values from the request and overwrites the old values. If the request came from a standard UI edit page, Salesforce runs system validation to check the record for:

• Compliance with layout-specific rules

• Required values at the layout level and field-definition level

• Valid field formats

• Maximum field length  Salesforce doesn't perform system validation in this step when the request comes from other sources, such as an Apex application or a SOAP API call.

.3. Executes all before triggers.

.4. Runs most system validation steps again, such as verifying that all required fields have a non-null value, and runs any user-defined validation rules. The only system validation that Salesforce doesn't run a second time (when the request comes from a standard UI edit page) is the enforcement of layout-specific rules.

Using the immediate=true attribute on a component that submits the page (commandbutton, commandlink, actionfunction) does skip validation, but this is because the user input is discarded, as detailed in a response in this thread from one of the Salesforce product managers:

I've worked around this in the past using a hidden field on the record that is only set via Apex, which indicates to the validation rule that it should allow the record through regardless. I wrote it up a while back in the following blog post:

Attribution to: Bob Buzzard
This content is remixed from stackoverflow or stackexchange. Please visit

My Block Status

My Block Content