Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7984023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:08:15+00:00 2026-06-04T11:08:15+00:00

I’m attempting to create my first VF page. It is a line-item entry form

  • 0

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_c) before clicking save. Right now, I’m opening the VF page from a custom button on the parent (Assure_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 ?

//page    

<apex:page standardController="Enfants__c" extensions="insererEnfants" standardStylesheets="true">
<apex:sectionHeader title="Ajouter un enfant"
    subtitle="{!$User.FirstName}" help="/help/doc/user_ed.jsp?loc=help"></apex:sectionHeader>
<apex:form >
    <apex:pageBlock title="Nouveau enfant" id="thePageBlock" mode="edit">
        <apex:pageBlockButtons >
            <apex:commandButton action="{!save}" value="Enregistrer"></apex:commandButton>
            <apex:commandButton action="{!cancel}" value="   Annuler   "></apex:commandButton>
        </apex:pageBlockButtons>

        <apex:pageBlockTable value="{!accts}" var="a" id="table">
            <apex:facet name="footer">
                <apex:commandLink value="Ajouter" action="{!addRow}" rerender="table,error"/>
            </apex:facet>
            <apex:facet name="header">
                <apex:commandLink value="Supprimer" action="{!deleteRow}" rerender="table,error"/>
            </apex:facet>

            <apex:column headerValue="Nom">
                <apex:inputField/> value="{!a.Parent__c}"/>
            </apex:column>
            <apex:column headerValue="Nom">
                <apex:inputField value="{!a.Name}"/>
            </apex:column>
            <apex:column headerValue="Prénom">
                <apex:inputField value="{!a.Prenom__c}"/>
            </apex:column> 
                            <apex:column headerValue="Né le">
                <apex:inputField value="{!a.Date_de_naissance__c}"/>
            </apex:column>   
                            <apex:column headerValue="Lieu de naissance">
                <apex:inputField value="{!a.Lieu_de_naissance__c}"/>
            </apex:column>   
                            <apex:column headerValue="Situation">
                <apex:inputField value="{!a.Situation__c }"/>
            </apex:column>                          
        </apex:pageBlockTable>
        </apex:pageblock>
</apex:form>
</apex:page>


//Controller


public class insererEnfants{


public List<Enfants__c> accts {get; set;}


public insererEnfants(ApexPages.StandardController controller){
    accts = new List<Enfants__c>();
    accts.add(new Enfants__c();

}

public void addrow(){
    accts.add(new Enfants__c());       
}

public PageReference deleteRow(){
   if (accts.size()>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;
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T11:08:16+00:00Added an answer on June 4, 2026 at 11:08 am

    First, you have no reference to the Parent object. You can solve this two ways:

    Solution 1:

    Pass the ID of the parent using a URL button, with something like the following as the URL:

    /apex/EnfantsPage?assureid={!Assure_c.Id}
    

    Replace “EnfantsPage” with the name of your VF page. Then, within the controller:

    String assureid = ApexPages.currentPage().getParameters().get('assureid');
    

    Now you know the ID of the parent. When you create a new child record, set the value of the parent id to id you have passed.

    public insererEnfants(ApexPages.StandardController controller){
      accts = new List<Enfants__c>();
      if (assureid <> null) {
        for (Assure__c assure: [ SELECT Id FROM Assure__c
                                 WHERE Id = :assureid] ) {
        accts.add(new Enfants__c( Parent__c = assure.Id ));
      } else {
        accts.add(new Enfants__c());  
      }
    }
    
    public void addrow(){
      if (assure.Id <> null) {
        accts.add(new Enfants__c( Parent__c = assure.Id ));
      } else {
        accts.add(new Enfants__c());  
      }      
    }
    

    Solution 2:

    Instead of extending the child controller, extend the parent:

    public Assure__c parent {get;}
    public List<Enfants__c> accts {get; set;}
    public insererEnfants(ApexPages.StandardController stdController) {
      this.parent = (Assure__c)stdcontroller.getRecord();
      accts.add(new Enfants__c( Parent__c = parent.id );
    }
    
    public void addrow(){
      accts.add(new Enfants__c( Parent__c = parent.id );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.