You need to sign in to do that
Don't have an account?

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:pageBlockButtons> <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:panelGrid> </apex:pageBlockSection> <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:commandButton> </apex:panelGrid> <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:panelGrid > <apex:facet name="header">City</apex:facet> <apex:inputfield value="{!e1.acct.City__c}"/> </apex:panelGrid> <apex:panelGrid > <apex:facet name="header">State</apex:facet> <apex:inputfield value="{!e1.acct.State__c}"/> </apex:panelGrid> <apex:panelGrid title="SPD" > <apex:facet name="header">Headcount</apex:facet> <apex:inputfield value="{!e1.acct.Head_count__c}"/> </apex:panelGrid> <apex:panelGrid > <apex:facet name="header">Number of Shifts</apex:facet> <apex:inputfield value="{!e1.acct.Number_of_Shifts__c}"/> </apex:panelGrid> <apex:panelGrid > <apex:facet name="header">Job Titles</apex:facet> <apex:inputfield value="{!e1.acct.Job_Titles__c}"/> </apex:panelGrid> </apex:panelgrid> </apex:repeat> </apex:pageBlock> </apex:pageblock> </apex:form> </apex:page>
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 {get;set;} //no. of rows added/records in the inner class list public Integer count = 1; //{get;set;} ////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++) { lstAcct.add(lstInner[j].acct); } insert lstAcct; pr.setRedirect(True); return pr; } //add one more row public void Add() { count = count+1; addMore(); } /*Begin addMore*/ public void addMore() { //call to the iner class constructor innerClass objInnerClass = new innerClass(count); //add the record to the inner class list lstInner.add(objInnerClass); system.debug('lstInner---->'+lstInner); }/* end addMore*/ /* begin delete */ public void Del() { system.debug('selected row index---->'+selectedRowIndex); lstInner.remove(Integer.valueOf(selectedRowIndex)-1); count = count - 1; }/*End del*/ /*Constructor*/ public MultiAdd1(ApexPages.StandardController ctlr) { lstInner = new List<innerClass>(); addMore(); 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 {get;set;} public Client_Site__c acct {get;set;} /*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*/
<apex:commandbutton value="Save " action="{!Save}" immediate="true'/>