0

My query is when I input account details after that input contact detail and click on the save button its not save given error is

Insert failed. First exception on row 0; first error: FIELD_FILTER_VALIDATION_EXCEPTION, Value does not exist or does not match filter criteria.: [AccountId]*

controller:-

public class AccountContactController{
public Account acc{get;set;}
public List<Contact> cont{get;set;}
public AccountContactController(){
    acc = new Account();
    cont = new List<Contact>();
    AddRow();
    AddRow();
    AddRow();

}
public void AddRow(){
    cont.add(new Contact());

}
public void save(){
    if(acc.name != null){
        insert acc;
        List<contact> con = new List<contact>();
        for(Contact c : cont){
            c.AccountId = acc.id;
            con.add(c);

        }
        if(con != null){
            insert con;
        }
    }

}}

----vfpage-----

  <apex:page controller="AccountContactController">
  <apex:form >
      <apex:pageBlock >
        <apex:pageblocksection columns="2">
        <apex:inputField value="{!acc.name}"/>
        <apex:inputField value="{!acc.phone}"/>
        <apex:inputField value="{!acc.website}"/>
        <apex:inputField value="{!acc.Sic}"/>

    </apex:pageblocksection>      
    <apex:pageBlockSection columns="1">
        <apex:pageBlockTable value="{!cont}" var="contacts">
            <apex:column headerValue="First Name">
                <apex:inputField value="{!contacts.firstname}"/>
            </apex:column>
            <apex:column headerValue="Last Name">
                <apex:inputField value="{!contacts.lastname}"/>
            </apex:column>
            <apex:column headerValue="Email">
                <apex:inputField value="{!contacts.email}"/>
            </apex:column>
        </apex:pageBlockTable>
    </apex:pageBlockSection>
   <apex:pageBlockButtons >
    <apex:commandButton value="Save" action="{!save}"/>
    <apex:commandButton value="Add Row" action="{!AddRow}" immediate="true"/>
    </apex:pageBlockButtons>

  </apex:pageBlock> 

  • Can you post the VF Page code that you have written? – Dhananjay Patil Jul 29 '17 at 6:45
  • @dhananjayPatil i have added vfpage – cloudZigZag Jul 29 '17 at 6:57
  • Do you mind sharing the test class for your controller? Thanks. – ultima67 Jul 15 '18 at 23:57
1

Your code is correct. We get this error when we have lookup filter enable. So check if you have lookup filter enable on contact for Account or you have second lookup related to Account which have lookup filter enable.

Just check the condition and update the Account record to match the condition it will solve your problem.

  • yes filter is enable . i have disabled and then run its save Thanks!! – cloudZigZag Jul 29 '17 at 7:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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