+ Start a Discussion

Parent Look Up Field In Visual Force page

I have two Objects , Client Discovery and Client Site . Client Site is having a Master Detail RelationShip with Client Discovery. Client discovery can have many Sites. So i created a visual force page to insert Client Discovery and on the same page using Add row functionality gave option to Create Client Sites. And when i hit save there is an error saying required fields are missing As by that Client Discovery is not yet created . 
<apex:page StandardController="Client_Discovery__c" extensions="MultiAdd1" id="thePage" sidebar="false">
<apex:sectionHeader title="Client Discovery " subtitle="{!Client_Discovery__c.name}"/>
<apex:form >
<apex:pageblock id="pb" title="Large Client Sales Questions">
    <apex:pageBlockButtons >
        <apex:commandbutton value="Add Client Site" action="{!Add}" rerender="pb1"/>
        <apex:commandbutton value="Save " action="{!Save}"/>
        <apex:commandButton value="Cancel" action="{!cancel}"/>
    <apex:pageBlockSection title="Client Needs" columns="1">

<apex:panelGrid columns="2" style="white-space:nowrap;" >
<Apex:outputlabel Value="What are the client's pain points?" for="Question1"  style="font-size:11px;font-family:arial;"/>
<apex:inputField value="{!Client_Discovery__c.What_are_the_client_s_pain_points__c}" id="Question1" required="false"  />

        <apex:pageblock id="pb1" title="Client Site">
        <apex:repeat value="{!lstInner}" var="e1" id="therepeat">
                <apex:panelGrid columns="7">
                <apex:panelGrid headerClass="Name">
                    <apex:facet name="header">Del</apex:facet>
                    <apex:commandButton value="X" action="{!Del}" rerender="pb1">
                        <apex:param name="rowToBeDeleted" value="{!e1.recCount}" assignTo="{!selectedRowIndex}"></apex:param>
                <apex:panelGrid title="SPD" >
                    <apex:facet name="header">Client Site Name</apex:facet>
                    <apex:inputfield value="{!e1.acct.Client_Site_Name__c}"/>
                <apex:panelGrid >
                    <apex:facet name="header">City</apex:facet>
                    <apex:inputfield value="{!e1.acct.City__c}"/>
               <apex:panelGrid >
                    <apex:facet name="header">State</apex:facet>
                    <apex:inputfield value="{!e1.acct.State__c}"/>
             <apex:panelGrid title="SPD" >
                    <apex:facet name="header">Headcount</apex:facet>
                    <apex:inputfield value="{!e1.acct.Head_count__c}"/>
                <apex:panelGrid >
                    <apex:facet name="header">Number of Shifts</apex:facet>
                    <apex:inputfield value="{!e1.acct.Number_of_Shifts__c}"/>
                <apex:panelGrid >
                    <apex:facet name="header">Job Titles</apex:facet>
                    <apex:inputfield value="{!e1.acct.Job_Titles__c}"/>
public class MultiAdd1
    //will hold the account records to be saved
    public List<Client_Site__c>lstAcct  = new List<Client_Site__c>();
    //list of the inner class
    public List<innerClass> lstInner 
    {   get;set;    }
    //will indicate the row to be deleted
    public String selectedRowIndex
    //no. of rows added/records in the inner class list
    public Integer count = 1;
    ////save the records by adding the elements in the inner class list to lstAcct,return to the same page
    public PageReference Save()
        PageReference pr = new PageReference('/apex/MultiAdd');
        for(Integer j = 0;j<lstInner.size();j++)
        insert lstAcct;
        return pr;
    //add one more row
    public void Add()
        count = count+1;
    /*Begin addMore*/
    public void addMore()
        //call to the iner class constructor
        innerClass objInnerClass = new innerClass(count);
        //add the record to the inner class list
    }/* end addMore*/
    /* begin delete */
    public void Del()
        system.debug('selected row index---->'+selectedRowIndex);
        count = count - 1;
    }/*End del*/
    public MultiAdd1(ApexPages.StandardController ctlr)
        lstInner = new List<innerClass>();
        selectedRowIndex = '0';
    }/*End Constructor*/

    /*Inner Class*/
    public class innerClass
        /*recCount acts as a index for a row. This will be helpful to identify the row to be deleted */
        public String recCount
        public Client_Site__c acct 
        /*Inner Class Constructor*/
        public innerClass(Integer intCount)
            recCount = String.valueOf(intCount);        
            /*create a new account*/
            acct = new Client_Site__c();
        }/*End Inner class Constructor*/    
    }/*End inner Class*/
}/*End Class*/

Waqar Hussain SFWaqar Hussain SF
In your object(Client_Discovery__c) you have some required fields. You are not inserting these fields from your page while you are inserting new record.I think you are missing some required fields in your Client_Discovery__c object. Check your fields which is required and it is not in your visualforce page.
Dushyant SonwarDushyant Sonwar
I think your function might not be called and standard validation rule is striking you out. use immediate true
<apex:commandbutton value="Save " action="{!Save}" immediate="true'/>
Thanks for the reply guys. I  will try these two suggestions . But here is my doubt as i am trying to insert both parent and child in the same visual force page the page is erroring out sayig i do not have the parent ID. kind of like i am trying to insert account and contacts on the same page and i dont have the account id to load for the contacts.