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
bhanu_prakashbhanu_prakash 

Need to update and save child contact record from vf page with Pagination

Hi Team,

How can we update child record information from vf page and need to add pagination
controller :
public with sharing class DiplayRelatedContacts {
   public List<Account> accList{get;set;}
   public list<Contact> conList{get;set;}
   public String accId{get;set;}
   public DiplayRelatedContacts(){
       accList=[SELECT Id,Name,AccountNumber FROM Account LIMIT 10];
   
   }
    public PageReference dispalyContact() {
       if(accId != null)
        conList=[SELECT id,FirstName,LastName,Phone,Department,Birthdate FROM COntact WHERE AccountId=:accId];
        update conList;
        return null;
    }    

     public pagereference save() {
     	update accList;
     	update conList;
     	return null;
	}   
}
Vf page 
 
<apex:page controller="DiplayRelatedContacts" id="pg" lightningStylesheets="true">
    <apex:form id="frm">
        <apex:pageBlock id="pgblk" >
            <apex:pageBlockTable value="{!accList}" var="ac">
                <apex:column width="10px">
                    <input type="radio" name="group1" />
                    <apex:actionSupport event="onclick" action="{!dispalyContact}" ReRender="conpgblk" >
                        <apex:param assignTo="{!accId}" name="accname" value="{!ac.id}"/>
                    </apex:actionSupport>
                </apex:column>
                <apex:column value="{!ac.Name}" />
                <apex:column value="{!ac.AccountNumber}" />
            </apex:pageBlockTable>
        </apex:pageBlock>
        
        
        <div id="globaSearch" class="modal fade" role="dialog" width="100%">
            <div class="modal-dialog">
               <div class="modal-content">
                    <div class="modal-header">
                       <!-- <button type="button" class="close" data-dismiss="modal">&times;</button> -->
                        <h4 class="modal-title">Contacts</h4>
                    </div>
                    <div class="modal-body">      
                        <apex:pageBlock id="conpgblk" >
                            <apex:outputPanel rendered="{!conList.size == 0}">
                                <b> NO RELATED CONTACTS FOR THIS ACCOUNT .</b>
                            </apex:outputPanel>
                            <apex:outputPanel rendered="{!conList.size != 0}">
                                <apex:pageBlockTable value="{!conList}" var="con">
                                    <apex:column value="{!con.FirstName}" />
                                    <apex:column value="{!con.LastName}" />                                   
                                    <apex:column ><apex:facet name="header">Birthdate</apex:facet> <apex:inputField value="{!con.Birthdate}"/></apex:column>
                                    <apex:column ><apex:facet name="header">Department</apex:facet> <apex:inputField value="{!con.Department}"/></apex:column>
                                    <apex:column ><apex:facet name="header">Phone</apex:facet> <apex:inputField value="{!con.Phone}"/></apex:column>        
                                </apex:pageBlockTable>
                            </apex:outputPanel>
                         
                            <apex:commandButton value="Save" id="save"/> 
                        </apex:pageBlock>
                        
                    </div>
                    
                </div>
                
            </div>
        </div>
        
    </apex:form>
</apex:page>

It is fetching information of related contacts and unable to update save functionality .
 
Sandeep YadavSandeep Yadav
Hello bahnu, 
You have to pass a parameter to update the record using <apex:param> component of visualforce.
Try this code--
 
Controller---

public with sharing class AllAccounts 
{
    public List<Account> acList {get;set;}
    public List<Contact> conList {get;set;}   
    public string accId {get;set;}
    public string eml {get;set;}
    
    public AllAccounts()
    {   
        acList = new List<Account>();
        for(Account a : [select id,name,accountnumber from account limit 10])
        {
            acList.add(a);
        }
    }
    
    public void showContact()
    {
        conList = new List<Contact>();
        for(contact c : [select id,firstname,lastname,email,leadsource from contact where accountid =: accId])
        {
            conList.add(c);
        }      
    }
    
    public void save()
    {
        update conList;
    }
}
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

VF Page---

<apex:page controller="AllAccounts" >

  <apex:form >
      <apex:pageBlock title="Accounts">
          <apex:pageBlockTable value="{!acList}" var="ac">
              <apex:column width="10px">
                    <input type="radio" name="group1" />
                    <apex:actionSupport event="onclick" action="{!showContact}" ReRender="lab" >
                        <apex:param assignTo="{!accId}" name="accname" value="{!ac.id}"/>
                    </apex:actionSupport>
                </apex:column>
              <apex:column >
                 <apex:facet name="header">AccountName</apex:facet><apex:outputField value="{!ac.name}"/>
              </apex:column>
              <apex:column >
                  <apex:facet name="header">AccountNumber</apex:facet><apex:outputField value="{!ac.accountnumber}"/>
              </apex:column>
          </apex:pageBlockTable>
          
          <apex:pageBlock id="lab">
              <apex:outputPanel rendered="{!conList.size == 0}">
                  <b>No records for this account</b>
              </apex:outputPanel>
              
              <apex:outputPanel rendered="{!conList.size != 0}">                                 
                  <apex:pageBlockTable value="{!conList}" var="cn">
                      <apex:column value="{!cn.firstname}"/>
                      <apex:column value="{!cn.lastname}"/>
                      
                      <apex:column ><apex:facet name="header">Email</apex:facet><apex:inputField value="{!cn.email}" /></apex:column>                                                                                           
                      <apex:column ><apex:facet name="header">Leadsource</apex:facet><apex:inputField value="{!cn.leadsource}"/></apex:column>
                      
                      <apex:param name="em" value="{!eml}" assignTo="{!em}"/>
                  </apex:pageBlockTable>
          </apex:outputPanel>
          
          <apex:commandButton value="Save" action="{!save}" reRender="lan"/>
          </apex:pageBlock>
          
      </apex:pageBlock>
  </apex:form>
</apex:page>
Mark this as best answer if this helps you. 
Thanks 
Sandeep
 
bhanu_prakashbhanu_prakash
Thanks for update. Now its is done with save functionality . I want to embbed pagination into that vf page . Plz help