2

I'm trying to loop the list of records and add to the selectedAccounts only if the isSelected == true

If you look at the data and you will find the record of Jolly is selected == true. but in my case its never adding to to the selectedAccount.

for(accountwrapper  accwrapper : accountList)
{
  if(accwrapper.isSelected == true)
  {
    selectedAccounts.add(accwrapper.oAccount);
  } 
}

Here is my accountList data spitting:

AccountWrapper:
[contactset=(
    ContactWrapper:[isSelected=false, oContact=Contact:{AccountId=0011a000004L8AdAAK, Id=0031a000007hwc2AAA, Name=John}],       
    ContactWrapper:[isSelected=true, oContact=Contact:{AccountId=0011a000004L8AdAAK, Id=0031a000007jjANAAY, Name=Jolly}], 
    ContactWrapper:[isSelected=false, oContact=Contact:{AccountId=0011a000004L8AdAAK, Id=0031a000007jjAWAAY, Name=Harry, Email=, Phone=}]), 
    isSelected=false,   
    oAccount=Account:{Id=0011a000004L8AdAAK, Name=BMW, BillingCountry=USA, CreatedById=0051a000000QWaBAAW}
]

Here is my code trying to add to the selectedAccounts only if the isSelected == true

    public class AccountWrapper
    {
        public account oAccount{get;set;}
        public boolean isSelected{get;set;}
        public List<ContactWrapper> contactset{get;set;}

        public AccountWrapper(account a, boolean b, List<ContactWrapper> c)
        {
            oAccount=a;
            isSelected=b;
            contactset =c;            
        }
    }  

    public class ContactWrapper
    {
        public Contact oContact { get; set; }
        public boolean isSelected { get; set; }

        public ContactWrapper(Contact a)
        {
            oContact=a;
            isSelected=false;                       
        }
    }
5
  • Try putting a system.debug() just before your if condition to see if the isSelected is indeed getting set as true when you are creating your list.
    – Aayush K
    Commented Jul 16, 2015 at 17:50
  • 4
    You're confusing your contacts for your accounts. The contact wrapper is selected, but the account wrapper is not. There's nothing wrong with your code.
    – sfdcfox
    Commented Jul 16, 2015 at 17:51
  • i'm not sure i understand but if you look at the data it is setting isSelected = true and what you see is that i'm trying to read the data from accountlist
    – Nick
    Commented Jul 16, 2015 at 17:51
  • @sfdcfox: yes i think so too so should i be using contactwrapper instead of accountwrapper?, i'm confused too :)
    – Nick
    Commented Jul 16, 2015 at 17:52
  • 3
    @AbuHamzah You have Accounts that contain lists of Contacts. Both have a selection Boolean value. Jolly is a Contact on the Account. The Account is not selected, and the Contact is. If you want to find your Contacts that are selected, you'll want to loop through each Account wrapper, then through each Contact wrapper.
    – sfdcfox
    Commented Jul 16, 2015 at 17:55

1 Answer 1

0

You have Accounts that contain lists of Contacts. Both have a selection Boolean value. Jolly is a Contact on the Account. The Account is not selected, and the Contact is. If you want to find your Contacts that are selected, you'll want to loop through each Account wrapper, then through each Contact wrapper.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .