function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
brielea1984brielea1984 

Passing Parent Object Info to Child in Multiple Entry Visualforce Page

Hi there,

 

I've created a quick entry visualforce page, which I got from this old Discussion Board post: Here

 

The Household (Households__c) object, is a child of the Case object with the Case ID lookup field on the Household object called Screening Number (Screening_Number__c). The child relationship name is Households__r.

 

The Contact object is a child of both the Household object and the Case object (follow me?). So the Contact object also has a lookup field to the Case object called Screening Number. (Field API: Screening_Number__c, Child relationship: Contacts__r)

 

I've recreated the code from the link above to be able to create multiple contact on the household object quickly. The household ID passes fine, but I'd love it if I could get the Screening Number field autopopulated in the table for quick entry.

 

Here is my Controller:

public class AddMultipleContacts {

    public List<Contact> cont {get; set;}
    private final Households__c parCont;
    public AddMultipleContacts(ApexPages.StandardController myController) {
        parCont=(Households__c)myController.getrecord();
        cont = new List<Contact>();
        Contact Hshld = new Contact();
        Hshld.Household_ID_del__c = parCont.id;
        cont.add(Hshld);}

    public void addrow() {
        Contact Hshld = new Contact();
        Hshld.Household_ID_del__c = parCont.id;
        cont.add(Hshld);}
            
    public void removerow(){
        Integer i = cont.size();
        cont.remove(i-1);}
            
    public PageReference save() {
        insert cont;
        //PageReference home = new PageReference('/home/home.jsp');
        //home.setRedirect(true);
        //return home; }}
        PageReference parrec = new PageReference('/'+parCont.id);
        parrec.setRedirect(true);
        return parrec; }}

 And here is my visualforce page:

 

<apex:page standardController="Households__c" extensions="AddMultipleContacts" sidebar="false">
    <apex:form >
    <apex:pageBlock title="Multiple Contact Quick Entry"  >
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}" rerender="error" />
                        <div style="text-align:right;margin-right:30px;font-weight:bold;">
            <apex:commandLink value="Add Row" action="{!addRow}" rerender="table,error" immediate="true" />
&nbsp;|&nbsp;&nbsp;
            <apex:commandLink value="Remove Row" action="{!removeRow}" rerender="table,error" immediate="true" />                
        </div>
            </apex:pageBlockButtons>
<b>Household Screening Number: </b>
<apex:outputField value="{!Households__c.Screening_Number__c}"/>
            <apex:pageBlockTable value="{!cont}" var="a" id="table">

                <apex:column headerValue="First Name">
                    <apex:inputField value="{!a.FirstName}"/>
                   
                </apex:column>                
                <apex:column headerValue="Last Name">
                    <apex:inputField value="{!a.LastName}"/>
                </apex:column>
                <apex:column headerValue="Screening Number">
                    <apex:inputField value="{!a.Screening_Number__c}" required="true"/>
                </apex:column>
                <apex:column headerValue="Birthdate">
                    <apex:inputField value="{!a.Birthdate}" required="false"/>
                </apex:column>
                <apex:column headerValue="Primary?">
                    <apex:inputField value="{!a.Primary_Contact_del__c}" required="false"/>
                </apex:column>
                <apex:column headerValue="Household Role">
                    <apex:inputField value="{!a.Family_Household_Role__c}" required="false"/>
                </apex:column> 
                <apex:column headerValue="Status">
                    <apex:inputField value="{!a.Case_Status__c}" required="true"/>
                </apex:column>                
                <apex:column headerValue="Privacy">
                    <apex:inputField value="{!a.Privacy__c}" required="true"/>
                </apex:column>                                                                   
            </apex:pageBlockTable>
 
    </apex:pageBlock>
    </apex:form>
</apex:page>

  Any advice would be much appreciated. I tried adding Hshld.Screening_Number__c = parCont.id; beneath Hshld.Household_ID_del__c = parCont.id; on the controller, but it didn't take. Any ideas?

 

Thanks!