0

I am querying account records and adding it to the list which in turn returns the values for another method called getSelected.I cleared the list just because its returning the previously selected values as shown

Partial code of page:

<apex:repeat value="{!alphabets}" var="a">
<apex:commandLink value="{!a}"  action="{!Alphabetorder}"  style="{!if($CurrentPage.parameters.alpha=a,'font-weight:bold','')}"  >
<apex:param name="alpha" value="{!a}"/>
</apex:commandLink>

&nbsp;|&nbsp;
 </apex:repeat>
            <apex:pageBlockSection Title="List of Available Accounts">

             <apex:dataTable value="{!accounts}" var="a" columnswidth="50px,50px"
                    cellpadding="4" border="1" styleClass="a-table">
                    <apex:column >
                        <apex:facet name="header">
                            <apex:inputCheckbox >
                                <apex:actionSupport event="onclick" action="{!GetSelected}"
                                    onsubmit="checkAll(this)" rerender="Selected_PBS" />
                            </apex:inputCheckbox>

Partial code of class:

  public PageReference Alphabetorder()
  {
  getAccounts();
  return null;
  } 
public List<accountwrapper> getAccounts()
{

 **accountList.clear();**
string s1;
   if(apexpages.currentpage().getparameters().get('alpha') == 'All')
       s1='%';
   else

       s1= apexpages.currentpage().getparameters().get('alpha')+'%';
       system.debug('alphabet ordering'+s1);

    for(Account acc: [Select a.Name, a.RecordTypeId, a.Phone, a.ParentId, a.Ownership, a.OwnerId, a.AccountNumber, (Select Id From Contacts), (Select Id From Opportunities)  From Account a where a.Name like :s1  ]) {
        System.debug('Account>>>>>>>>>>>>'+acc+acc.contacts.size());
        accountList.add(new accountwrapper(acc,acc.opportunities.size(),acc.contacts.size()));
    }
     //System.debug('account recordssss'+accountList);

    return accountList;

}

public PageReference getSelected()
{
    for(accountwrapper accwrapper: accountList)
    if(accwrapper.selected == true)
    selectedAccounts.add(accwrapper.acc);
                  System.debug('selected values'+selectedAccounts);

           return null;


}

Now since the return AccountList will become null it can't be used for getselected method? Where should I clear if that's the case?

1

On UI you are processing Accounts list and in controller you are referring accountlist. Use accountlist in VF page and you will get updated value.

| improve this answer | |
  • @tushar.thats a wrapper class list.I am calling get accounts method in visualforce page – Priyalakshmi Aug 20 '16 at 20:34
  • @Pri yes but use accountlist for processing because whenever section rerender it clear youfr old value so you will never get updated value in Getselected method. – Tushar Sharma Aug 20 '16 at 20:38
  • 1
    Thankyou so much@ tushar.I am able to get it now.I just have one more doubt.Based on my question,I have used jquery for pagination but for every new page its not retaining the previously selected page record.its only storing the current page record.How to rectify it? – Priyalakshmi Aug 20 '16 at 20:46
  • @Pri for that you need maintain selected record in a set and when you fill the list check if account Od exist in set check true. – Tushar Sharma Aug 21 '16 at 4:16
  • Tushar,I have posted a new question based on your comment and added the set as you said.Still its not working.Please check whether its right – Priyalakshmi Aug 21 '16 at 18:08
0

You don't have to clear your list. You just initialize you list in method getAccounts. Once you initialize it will remove all the content from the list.

accountList = New List<Account>();
| improve this answer | |
  • When do you call getAccount methed on page load ? – MIX DML Aug 20 '16 at 20:02
  • when the alphabet is selected.which is actually assigned to s1 as you can see in code – Priyalakshmi Aug 20 '16 at 20:05
  • I have updated my question – Priyalakshmi Aug 20 '16 at 20:08

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.