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;                       
        }
    }
  • 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 Jul 16 '15 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 Jul 16 '15 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 Kahn Jul 16 '15 at 17:51
  • @sfdcfox: yes i think so too so should i be using contactwrapper instead of accountwrapper?, i'm confused too :) – Nick Kahn Jul 16 '15 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 Jul 16 '15 at 17:55
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.

| improve this answer | |

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.