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
Ramana123Ramana123 

My page is not getting refreshed even though i am using reRender for the entire page in salesforce (I want to refresh entire page))

How to make it work Rerender

Class


public class AccountRelatedContactsWithCheckBox {
   public List<AccountRelatedContactWrapper> consList {get;set;}
   public List<Contact> selectedConList {get;set;}
    public AccountRelatedContactsWithCheckBox(ApexPages.StandardController stdController)
    {
        if(consList == null) {
            consList = new list<AccountRelatedContactWrapper>();
            selectedConList = new list<Contact>();
            for(contact a:[select id,LastName,AccountId from contact where AccountId = : ApexPages.currentPage().getParameters().get('id')]) 
            {
                consList.add(new AccountRelatedContactWrapper(a));
            }            
        }
        System.debug('aaaaaaaaaa'+consList);
    }          
    public void deleteSelectedRecords()
    {               
         for(AccountRelatedContactWrapper wrapobj:consList){
            if(wrapobj.selected==true) {   
            selectedConList.add(wrapobj.con);              
            } 
        }         
        delete selectedConList;
        if(selectedConList.size() > 0) {
        ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Info,'Record Deleted successfully'));
          }
    }        
    public void updateSelectedRecords()
    {       
       for(AccountRelatedContactWrapper wrapobj:consList){
            if(wrapobj.selected==true) {   
            selectedConList.add(wrapobj.con);              
            } 
        } 
        upsert selectedConList;
        if(selectedConList.size() > 0)
        {
        ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Info,'Record updated successfully'));
        }
    }    
    public void creatingNewRecord()
    {    
    // Creates a new wrapper that will display a new entry on the page.
    AccountRelatedContactWrapper wrapper = new AccountRelatedContactWrapper(new contact());
    // Creates a record in memory for user input.
    wrapper.con = new Contact(
    AccountId = ApexPages.currentPage().getParameters().get('id')
    );
    // Adds the wrapper to the list of wrappers
    consList.add(wrapper);
}       
    public class AccountRelatedContactWrapper
    {
       public Contact con {get;set;}
       public Boolean selected {get;set;}        
       public AccountRelatedContactWrapper(Contact con1)
        {
            con = con1;  
            selected = false;
        }
    }
}


page

<apex:page standardController="Account" extensions="AccountRelatedContactsWithCheckBox" id="page1">
    <apex:form title="Titles">
        <apex:pageblock title="Account Related Contacts">          
              <apex:pageMessages id="message"></apex:pageMessages>
                <apex:pageBlockTable value="{!consList}" var="conWrap" title="All Contacts" summary="Account Related Contacts">
                   <apex:column >                        
                       <apex:inputCheckbox value="{!conWrap.selected}"/>
                   </apex:column>
                   <apex:column headerValue="First Name">
                       <apex:inputField value="{!conWrap.con.LastName}"/>
                   </apex:column>
             </apex:pageBlockTable>      
       </apex:pageblock>    
       <apex:commandButton value="Delete Selected Records" action="{!deleteSelectedRecords}" reRender="page1" title="select the checkbox and click the button"/>
       <apex:commandButton value="Create Records" action="{!creatingNewRecord}" title="select the checkbox and click the button"/> 
       <apex:commandButton value="Save selected Records" action="{!updateSelectedRecords}" title="select the checkbox and click the button"/>
   </apex:form>
</apex:page>





 
Best Answer chosen by Ramana123
SwethaSwetha (Salesforce Developers) 
HI Ramana,

Edit your highlighted line to this
<apex:commandButton value="Delete Selected Records" action="{!deleteSelectedRecords}" reRender="page1" title="select the checkbox and click the button" oncomplete="window.top.location.reload()" />

If this information helps, please mark the answer as best.Thank you

All Answers

SwethaSwetha (Salesforce Developers) 
Hi Ramana,
I could test your code in my dev org. Your ask seems similar to https://salesforce.stackexchange.com/questions/37392/refresh-page-with-command-button-rerender-attribute-set according to which 

If you do not provide the rerender attribute on the commandbutton then the whole page will refresh.

You can also provide multiple ids in your rerender attribute separated by commas (,). So with that you can refresh different sections of the page.

Related: https://salesforce.stackexchange.com/questions/185254/how-to-stop-refreshing-the-entire-vf-page-when-command-link-is-clicked

If this information helps, please mark the answer as best.Thank you
Ramana123Ramana123
Hi Swathi, Thanks For the help . But when the page is refreshing still the deleted contact is displaying on the vf page
SwethaSwetha (Salesforce Developers) 
HI Ramana,

Edit your highlighted line to this
<apex:commandButton value="Delete Selected Records" action="{!deleteSelectedRecords}" reRender="page1" title="select the checkbox and click the button" oncomplete="window.top.location.reload()" />

If this information helps, please mark the answer as best.Thank you
This was selected as the best answer
Ramana123Ramana123
Thanks Swathi, It's working now.