Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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">
        <style>
        .headerRow th{
            display:none;
        }
        </style>
          <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>
                              <br/>
                              <apex:commandLink action="{!action}" immediate="true">
                                  <apex:image value="{!$Resource.Logo_Transparent}" height="50" width="200" />
                              </apex:commandlink>
                               </apex:form>
                          </apex:pageblocksection>
                      </apex:pageblock>
                  </apex:tab>
                  <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:pageBlockButtons>
                              <apex:pageblocksection >
                                  <apex:pageBlockTable value="{!Opportunities}" var="Opportunity" > 
                                      <apex:column headerValue="RecordTypeId" value="{!Opportunity.RecordTypeId}" />
                                      <apex:column headerValue="Name" value="{!Opportunity.name}" />
                                      <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:pageBlockTable>
                              </apex:pageblocksection>
                              <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:selectList>
                                  <apex:inputField label="deal with" value="{!lead.LastName}" />&nbsp;
                                  <apex:inputField label="Duration" value="{!event.DurationInMinutes}"/>&nbsp;
                              </apex:pageBlockSection>
                              <apex:pageBlockSection title="Opportunity Information" columns="2">
                                  <apex:inputField value="{!ObjOpportunity.name}"/>
                                  <apex:inputField value="{!ObjOpportunity.StageName}"/>
                                  <apex:inputField value="{!ObjOpportunity.AccountId}"/>
                                  <apex:inputField value="{!ObjOpportunity.CloseDate}"/>
                              </apex:pageBlockSection>
                      </apex:pageblock> 
                      </apex:form> 
</apex:tabPanel>
 </apex:page>
share|improve this question
    
How about just search for the error text that you encounter and check which validation rule it matches up to. you can then tackle the problem at the source. –  techtrekker Dec 10 '12 at 13:52
    
I see input for LastName, but not for Company. Are you providing that in the controller? Company is a required field unless Person Accounts are enbled. –  zjeh Dec 10 '12 at 16:20
add comment

2 Answers 2

up vote 2 down vote accepted

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

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

Edited: Refer the link here

share|improve this answer
1  
+1 .Using immediate=true avoids validation –  Mohith Shrivastava Dec 10 '12 at 11:59
    
Thanks Guys for quick Reply I placed Immediate attribute next in commandButton but still I'm getting same error msg System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, You must review the preferences section before you can save this record: [] Error is in expression '{!dosave}' in component <apex:page> in page Opportunity –  rakesh Dec 10 '12 at 12:08
1  
Which object record you are trying to insert ? –  Priyanka Dec 10 '12 at 12:15
1  
Is the error from validation rule or trigger.. Check if the error is from trigger.. Coz immediate=true will only work on validation rules –  Priyanka Dec 10 '12 at 12:49
5  
Using immediate=true doesn't just avoid validation rules, it also discards any user input since the last postback. –  Bob Buzzard Dec 11 '12 at 8:38
show 12 more comments

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:

http://boards.developerforce.com/t5/Visualforce-Development/If-immediate-quot-true-quot-rerender-does-not-appear-to-work/td-p/77657

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:

http://bobbuzzard.blogspot.co.uk/2011/11/bypass-validation-rules-from-apex.html

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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