• harry.31
  • NEWBIE
  • 0 Points
  • Member since 2010

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies

I have a very simple VF page, trying to insert a new record, but the Apex:inputField didn't work for lookup field.

 

Following is the sample code:

 

<apex:page controller="contactController">
    <apex:form >
        <apex:pageBlock>
            <apex:pageBlockTable value="{!contacts}" var="con">
                <apex:column value="{!con.Id}" headerValue="FP #">
                    <apex:facet name="footer">
                        <apex:commandLink value="Add" action="{!add}"/>
                    </apex:facet>
                </apex:column>
                <apex:column value="{!con.AccountId}" headerValue="account">
                    <apex:facet name="footer">
                        <apex:inputField value="{!contact.AccountId}" required="true"/>
                    </apex:facet>
                </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 

public class contactController 
{
    public assigntravelrates()
    {
        Contact = new Contact();
        Contacts = [select Id, AccountId from Contact limit 2];
    }
    public List<contact> Contacts { get; set; }
    public Contact Contact { get; set; }
    public void add()
    {
        insert Contact;
    }
}

 

when I first time clicks the lookup icon and clicks the add link, it throws a error says "you must enter a value", then I choose the account again, it throws the "required field missing" error which is correct.

 

 

Did anyone have met the same issue?

I have a very simple VF page, trying to insert a new record, but the Apex:inputField didn't work for lookup field.

 

Following is the sample code:

 

<apex:page controller="contactController">
    <apex:form >
        <apex:pageBlock>
            <apex:pageBlockTable value="{!contacts}" var="con">
                <apex:column value="{!con.Id}" headerValue="FP #">
                    <apex:facet name="footer">
                        <apex:commandLink value="Add" action="{!add}"/>
                    </apex:facet>
                </apex:column>
                <apex:column value="{!con.AccountId}" headerValue="account">
                    <apex:facet name="footer">
                        <apex:inputField value="{!contact.AccountId}" required="true"/>
                    </apex:facet>
                </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 

public class contactController 
{
    public assigntravelrates()
    {
        Contact = new Contact();
        Contacts = [select Id, AccountId from Contact limit 2];
    }
    public List<contact> Contacts { get; set; }
    public Contact Contact { get; set; }
    public void add()
    {
        insert Contact;
    }
}

 

when I first time clicks the lookup icon and clicks the add link, it throws a error says "you must enter a value", then I choose the account again, it throws the "required field missing" error which is correct.

 

 

Did anyone have met the same issue?