Skip to main content
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>

 
4 个回答
  1. 2021年3月4日 14:03
    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
0/9000