0

I am using a custom button on the parent Custom Object page which will launch a VF page to allow the user to input one or many child records. I would like to pre-populate the Parent Id for each new row added so the user does not have to perform a lookup themselves to the parent. How is this possible?

VF:

    <apex:page controller="AddSites">
    <apex:form >
    <apex:pageBlock >
        <apex:pageBlockTable value="{!listSite}" var="site">
            <apex:column headerValue="Site Name">
                <apex:inputField value="{!site.Account__c}"/>
            </apex:column>
            <apex:column headerValue="Contract Term">
               <apex:inputField value="{!site.ContractTerm__c}"/> 
            </apex:column>            
        </apex:pageBlockTable>
        <apex:pageBlockButtons >
            <apex:commandButton value="Add Site" action="{!addSite}"/>
            <apex:commandButton value="Save" action="{!saveSite}"/>
        </apex:pageBlockButtons>
    </apex:pageBlock>
    </apex:form>
</apex:page>

Apex:

public class AddSites {

    Site__c sites = new Site__c();
    public list<Site__c> listSite{ get; set; }
    public String parentId=  

    public AddSites() {
      listSite=new list<Site__c>();
      listSite.add(sites);

    }

    Public void addSite () {
      Site__c site = new Site__c();
      //listSite.add(site);      

    }

    public PageReference saveSite() {
        for(Integer i=1; i<listSite.size(); i++) {
            insert listSite;
        }
        return Page.AllSitesSaved;

    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.