title: Passing parent id to child record in VisualForce page
body: <p>I'm attempting to create my first VF page. It is a line-item entry form that will allow a user to enter multiple child records (Enfants_<em>c) before clicking save. Right now, I'm opening the VF page from a custom button on the parent (Assure</em>_c). However, when the page opens, the lookup field for the parent is not populated - so the user has to click the lookup to select the parent from Assure__c. Is there a way to pass the parent id of the previous page to the new child records on the VF page ?</p>
  
  <pre><code>//page    
  
  &lt;apex:page standardController="Enfants__c" extensions="insererEnfants" standardStylesheets="true"&gt;
  &lt;apex:sectionHeader title="Ajouter un enfant"
      subtitle="{!$User.FirstName}" help="/help/doc/user_ed.jsp?loc=help"&gt;&lt;/apex:sectionHeader&gt;
  &lt;apex:form &gt;
      &lt;apex:pageBlock title="Nouveau enfant" id="thePageBlock" mode="edit"&gt;
          &lt;apex:pageBlockButtons &gt;
              &lt;apex:commandButton action="{!save}" value="Enregistrer"&gt;&lt;/apex:commandButton&gt;
              &lt;apex:commandButton action="{!cancel}" value="   Annuler   "&gt;&lt;/apex:commandButton&gt;
          &lt;/apex:pageBlockButtons&gt;
  
          &lt;apex:pageBlockTable value="{!accts}" var="a" id="table"&gt;
              &lt;apex:facet name="footer"&gt;
                  &lt;apex:commandLink value="Ajouter" action="{!addRow}" rerender="table,error"/&gt;
              &lt;/apex:facet&gt;
              &lt;apex:facet name="header"&gt;
                  &lt;apex:commandLink value="Supprimer" action="{!deleteRow}" rerender="table,error"/&gt;
              &lt;/apex:facet&gt;
  
              &lt;apex:column headerValue="Nom"&gt;
                  &lt;apex:inputField/&gt; value="{!a.Parent__c}"/&gt;
              &lt;/apex:column&gt;
              &lt;apex:column headerValue="Nom"&gt;
                  &lt;apex:inputField value="{!a.Name}"/&gt;
              &lt;/apex:column&gt;
              &lt;apex:column headerValue="Prénom"&gt;
                  &lt;apex:inputField value="{!a.Prenom__c}"/&gt;
              &lt;/apex:column&gt; 
                              &lt;apex:column headerValue="Né le"&gt;
                  &lt;apex:inputField value="{!a.Date_de_naissance__c}"/&gt;
              &lt;/apex:column&gt;   
                              &lt;apex:column headerValue="Lieu de naissance"&gt;
                  &lt;apex:inputField value="{!a.Lieu_de_naissance__c}"/&gt;
              &lt;/apex:column&gt;   
                              &lt;apex:column headerValue="Situation"&gt;
                  &lt;apex:inputField value="{!a.Situation__c }"/&gt;
              &lt;/apex:column&gt;                          
          &lt;/apex:pageBlockTable&gt;
          &lt;/apex:pageblock&gt;
  &lt;/apex:form&gt;
  &lt;/apex:page&gt;
  
  
  //Controller
  
  
  public class insererEnfants{
  
  
  public List&lt;Enfants__c&gt; accts {get; set;}
  
  
  public insererEnfants(ApexPages.StandardController controller){
      accts = new List&lt;Enfants__c&gt;();
      accts.add(new Enfants__c();
  
  }
  
  public void addrow(){
      accts.add(new Enfants__c());       
  }
  
  public PageReference deleteRow(){
     if (accts.size()&gt;1)
     {
        accts.remove(accts.size()-1);
     }
     return null;
  }
  
  public PageReference save()
  {
      insert accts;
      Assure__c theParent = new Assure__c(id=accts[0].Parent__c);
      PageReference acctPage = new ApexPages.StandardController(theParent).view();
      acctPage.setRedirect(true);
      return acctPage;
  }
  }
  </code></pre>