Friday, 6 May 2022

reRender Parent VF page data when Child VF page in pop-up window is getting closed.

While working on one of the requirements for a Health sector solutions customer based out in Atlanta, Georgia, there was a requirement to reRender Parent Visualforce page data when another Child Visualforce page in Pop-up window is getting closed. 

Our main challenge was to call the JavaScript function in the Parent VF page from the child VF page in a pop-up window. 

  • Here the requirement was to open a VF page with the click of a button that creates a Contact record for a particular account, and after creating the contact record modify the contact table with the newly created contact.
  • To implement this requirement, we used custom JavaScript function and apex:actionFunction


<apex:page Controller="ContactListController" lightningStylesheets="true">
    <apex:slds />
    <apex:form >
        <apex:commandbutton value="Add Contact"
                 oncomplete="'/apex/AddContact?id={!accountId}', '_blank', 
                            'left=500, top=100, height=500px, width=500px');" />
        <apex:pageBlock id="ContactBlock">
            <apex:pageBlockTable value="{!contactList}" var="cnt" id="ContactList">
                <apex:column value="{!cnt.Name}"/>
                <apex:column value="{!}"/>
                <apex:column value="{!cnt.Email}"/>
        <apex:actionfunction name="reRenderContactListAF" 
                             reRender="ContactBlock,ContactList" />
        function reRenderContactList(){

  • In the above code, we used custom JavaScript and actionFunction to retrieve the newly created contact and reRender the components.

<apex:page Controller="ContactListController" lightningStylesheets="true">
    <apex:slds />
    <apex:form >
    	<apex:pageBlock title="Contact Form">           
        <apex:pageBlockSection columns="2">
            <apex:inputField value="{!newContact.FirstName}"/>
            <apex:inputField value="{!newContact.LastName}"/>
            <apex:inputField value="{!newContact.Email}"/>
            <apex:inputField value="{!newContact.Phone}"/>
        <apex:pageBlockButtons location="bottom">
            <apex:commandButton action="{!saveContact}" value="Save"
                         onclick="this.value='Saving ...';this.disabled=true"
                         oncomplete="this.value='Save';this.disabled=false;winClose()" />

    	function winClose(){

  • In the above code, winClose() function will be executed on click of Save button. And winClose() JavaScript function will call the reRenderContactList() JavaScript function of the opener VF page. 

public class ContactListController {   
    public Contact newContact{get; set;} 
    public List<Contact> contactList{get; set;}
    public string accountId{get; set;}
    public ContactListController(){        
        accountId = ApexPages.CurrentPage().getParameters().get('id');                    
        newContact = new Contact(AccountId=accountId);
    public void retrieveContacts(){
        contactList = [select Id, Name, Email, Phone 
                       from contact where AccountId=:accountId];
    public void saveContact(){ 
        upsert newContact;

  • So basically, whenever the save button gets clicked on VF page in the pop-up, it calls the JavaScript function winClose() and this function calls the JavaScript function of the Parent VF page.
  • JavaScript function of Parent VF page calls the apex:actionFunction which calls the controller method on its action attribute. 
  • After completion of controller method execution, apex:actionFunction rerenders some elements in the same component.



By using <apex:actionFunction> and JavaScript function effectively, we are able to reRender the contact table with the newly created contact. 

If you have any questions you can reach out our Salesforce Consulting team here.

No comments:

Post a Comment