You need to sign in to do that
Don't have an account?
Prema -
I am not getting the Contacts related to the Selected Accounts. Button is not working. Even if I give setter getter method accContacts then also it's giving the error that dereference to null.
I am not getting my Related Contact when i check the checkboxes. I am getting this error: The page you submitted was invalid for your session. Please refresh your page and try again.
VF: <apex:page controller="AccountWrapper" sidebar="false"> <apex:form > <apex:pageBlock > <apex:pageBlockButtons > <apex:commandButton value="Select" action="{!isSelected}" rerender="table"/> </apex:pageBlockButtons> <apex:pageBlockSection title="Accounts"> <apex:pageBlockTable value="{!wrapItems}" var="c" id="table"> <apex:column headerValue="Select"> <apex:inputCheckbox value="{!c.selected}"/> </apex:column> <apex:column value="{!c.accList.Name}" headerValue="Account Name"/> </apex:pageBlockTable> </apex:pageBlockSection> <!--<apex:pageblockSection title="Related Contacts"> <apex:pageBlockTable value="{!accContacts}" var="c1" id="table"> <apex:column value="{!c1.Name}" headerValue="Contact Name"/> </apex:pageBlockTable> </apex:pageblockSection>--> </apex:pageBlock> </apex:form> </apex:page> Controller: public class AccountWrapper { public List<WrapperAccounts> wrapItems{set;get;} public List<WrapperAccounts> selectedItem{set;get;} //public List<Contact> accContacts{set;get;} public AccountWrapper() { wrapItems=new List<WrapperAccounts>(); List<Account> accItem2=new List<Account>([SELECT Name FROM Account limit 10]); for(Account a1:accItem2) { boolean check=false; wrapItems.add(new WrapperAccounts(check,a1)); } } //Method to Fetch Records. public PageReference isSelected() { selectedItem=new List<WrapperAccounts>(); for(WrapperAccounts w:wrapItems) { if(w.selected==true) { fetchRecords(); } PageReference p=Page.WrapperReturn; return p; } return null; } //Method to define fetchRecords public void fetchRecords() { List<Contact> accContacts=new List<Contact>(); for(WrapperAccounts wraps : wrapItems) { for(Contact con:[Select Name from Contact WHERE AccountId!=null]) { if(wraps.selected) { accContacts.add(con); } } System.debug('Contacts Lists:'+accContacts); } } //Wrapper Class public class WrapperAccounts { public boolean selected{set;get;} public Account accList{set;get;} public WrapperAccounts(Boolean sel,Account acc) { this.accList=acc; this.selected=sel; } } }
I am not getting the Contacts related to the Selected Accounts. Button is not working. Even if I give setter getter method accContacts then also it's giving the error that dereference to null.