You need to sign in to do that
Don't have an account?
Prema -
Please let me know how can i get checked account's contacts and when i check contact it should show the record detail page. I have created the class but its not letting me to save one if the property.
public class AccountWrapper { public List<WrapperAccounts> wrapItems{set;get;} public List<WrapperAccounts> wrapConItems{set;get;} public List<WrapperAccounts> selectedItem{set;get;} public List<Contact> accContacts{set;get;} public Set<Id> accId=new Set<Id>(); public AccountWrapper() { wrapItems=new List<WrapperAccounts>(); List<Account> accItem2=new List<Account>([SELECT Name FROM Account limit 10]); wrapConItems=new List<WrapperAccounts>(); for(Account a1:accItem2) { boolean check=false; wrapItems.add(new WrapperAccounts(check,a1)); } if(accId!=null) { for(Contact cx:conwrap) { wrapConItems.add(new WrapperAccounts(false,cx)); } } } //Defining pagference to perform actionsupport onclick event public PageReference fetch() { fetchRecords(); return null; } public PageReference fetchCont() { fetchConRecords(); return null; } //Method to define fetchRecords which will fetch Related Contacts public void fetchRecords() { accContacts=new List<Contact>(); for(WrapperAccounts wraps : wrapItems) { if(wraps.selected==true) { accId.add(wraps.accList.Id); } System.debug('Selected Accounts:'+wraps); } System.debug('Accounts IDs:accId='+accId); List<Contact> cons=[Select Name from Contact WHERE AccountId IN:accId]; for(Contact con:cons) { accContacts.add(con); } System.debug('Contacts Lists:'+accContacts); } //method to fetch contact's detail page public Set<Id> conId=new Set<Id>(); public void fetchConRecords() { for(WrapperAccounts contwraps : wrapConItems) { if(contwraps.conSel==true) { conId.add(contwraps.contLists.Id); } System.debug('Selected Contacts:'+contwraps); } List<Contact> conx2=[Select Id from Contact WHERE Id IN:conId]; System.debug('Contacts Lists in conx2:'+conx2); } //Wrapper Class public class WrapperAccounts { public boolean selected{set;get;} public Account accList{set;get;} public Contact contLists{set;get;} public boolean conSel{set;get;} public WrapperAccounts(Boolean sel,Account acc) { this.accList=acc; this.selected=sel; } public WrapperAccounts(Boolean selec,Contact co) { this.conSel=selec; this.contLists=co; } } } <apex:page controller="AccountWrapper" sidebar="false"> <apex:form > <apex:pageBlock > <apex:pageBlockButtons > <!--<apex:commandButton value="Select" action="{!fetchRecords}" reRender="block2" rerender="block3"/>--> </apex:pageBlockButtons> <apex:pageBlockSection title="Accounts" columns="3"> <apex:pageBlockTable value="{!wrapItems}" var="c" id="table"> <apex:column headerValue="Select"> <apex:inputCheckbox value="{!c.selected}"/> <apex:actionSupport event="onclick" action="{!fetch}"/> </apex:column> <apex:column value="{!c.accList.Name}" headerValue="Account Name"/> </apex:pageBlockTable> <apex:pageBlockTable value="{!accContacts}" var="c1" id="block2"> <apex:column headerValue="Select"> <!--<apex:inputCheckbox value="{!c1.conSel}"/>--> <apex:actionSupport event="onclick" action="{!fetchCont}"/> </apex:column> <apex:column value="{!c1.Name}" headerValue="Related Contacts Name"/> </apex:pageBlockTable> <apex:pageBlockTable value="{!accContacts}" var="d1" id="block3"> <apex:column value="{!d1.Name}" headerValue="Contact Detail Page"/> </apex:pageBlockTable> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
Try this one
<apex:page controller="AccountWrapper" sidebar="false">
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons >
<!--<apex:commandButton value="Select" action="{!fetchRecords}" reRender="block2" rerender="block3"/>-->
</apex:pageBlockButtons>
<apex:pageBlockSection title="Accounts" columns="3">
<apex:pageBlockTable value="{!wrapItems}" var="c" id="table">
<apex:column headerValue="Select">
<apex:inputCheckbox value="{!c.selected}"/>
<apex:actionSupport event="onclick" action="{!fetch}"/>
</apex:column>
<apex:column value="{!c.accList.Name}" headerValue="Account Name"/>
</apex:pageBlockTable>
<apex:pageBlockTable value="{!wrapConItems}" var="c1" id="block2">
<apex:column headerValue="Select">
<apex:inputCheckbox value="{!c1.conSel}"/>
<apex:actionSupport event="onclick" action="{!fetchCont}"/>
</apex:column>
<apex:column value="{!c1.contLists.Name}" headerValue="Related Contacts Name"/>
</apex:pageBlockTable>
<apex:pageBlockTable value="{!conx2}" var="d1" id="DetailPageBlock">
<apex:column value="{!d1.Name} {!d1.Phone}" headerValue="Contact Detail Page"/>
<!--<apex:detail id=""/>-->
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
All Answers
May I know that the variable conwrap can be defined in which code
for(Contact cx:conwrap)
{
wrapConItems.add(new WrapperAccounts(false,cx));
}
Thanks
K.Kamala
Sweet Potato Tec
Thanks for your response. It was mistakenly removed i had a list i.e. List<Contact> conwrap=[select FirstName,LastName,Email from Contact WHERE AccountID IN:accId];
But please let me know how can i show checkbox beside every contact which i am getting once i click on the checkbox beside acocunt. Whenever i am trying to save this line it gives me error:
<!--<apex:inputCheckbox value="{!c1.conSel}"/>--> so i commented this.
Also how to show the selected contact's detail page in the third pageblock section. Please help me on this
Iam working on this issue i will get back to you after solved..
Thanks,
K.Kamala,
Sweet Potato Tec..
Thanks for your response. but i have updated the code. Now it's giving error for C1.FirstName and if i give only c1 then no error but i am not getting values in second block. Please check my updated code.
It's not invoking the Parameterized constructor. Hope you will get back soon to me after making this work 😊
Try this code:
<apex:page controller="AccountWrapper" sidebar="false">
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons >
<!--<apex:commandButton value="Select" action="{!fetchRecords}" reRender="block2" rerender="block3"/>-->
</apex:pageBlockButtons>
<apex:pageBlockSection title="Accounts" columns="3">
<apex:pageBlockTable value="{!wrapItems}" var="c" id="table">
<apex:column headerValue="Select">
<apex:inputCheckbox value="{!c.selected}"/>
<apex:actionSupport event="onclick" action="{!fetch}"/>
</apex:column>
<apex:column value="{!c.accList.Name}" headerValue="Account Name"/>
</apex:pageBlockTable>
<apex:pageBlockTable value="{!wrapConItems}" var="c1" id="block2">
<apex:column headerValue="Select">
<apex:inputCheckbox value="{!c1.conSel}"/>
<apex:actionSupport event="onclick" action="{!fetchCont}"/>
</apex:column>
<apex:column value="{!c1.contLists.Name}" headerValue="Related Contacts Name"/>
</apex:pageBlockTable>
<apex:pageBlockTable value="{!accContacts}" var="d1" id="DetailPageBlock">
<apex:column value="{!d1.Name}" headerValue="Contact Detail Page"/>
<!--<apex:detail id=""/>-->
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller:
public class AccountWrapper
{
public List<WrapperAccounts> wrapItems{set;get;}
public List<WrapperAccounts> wrapConItems{set;get;}
public List<WrapperAccounts> selectedItem{set;get;}
public List<Contact> accContacts{set;get;}
public Set<Id> accId=new Set<Id>();
public AccountWrapper()
{
wrapItems=new List<WrapperAccounts>();
List<Account> accItem2=new List<Account>([SELECT Name FROM Account limit 10]);
wrapConItems=new List<WrapperAccounts>();
List<Contact> conwrap=new List<Contact>([select FirstName,LastName from Contact WHERE AccountID IN:accId]);
for(Account a1:accItem2)
{
boolean check=false;
wrapItems.add(new WrapperAccounts(check,a1));
}
}
//Defining pagference to perform actionsupport onclick event
public PageReference fetch()
{
fetchRecords();
return null;
}
public PageReference fetchCont()
{
fetchConRecords();
return null;
}
//Method to define fetchRecords which will fetch Related Contacts
public void fetchRecords()
{
accContacts=new List<Contact>();
for(WrapperAccounts wraps : wrapItems)
{
if(wraps.selected==true)
{
accId.add(wraps.accList.Id);
}
System.debug('Selected Accounts:'+wraps);
}
System.debug('Accounts IDs:accId='+accId);
List<Contact> cons=[Select Name from Contact WHERE AccountId IN:accId];
for(Contact con:cons)
{
accContacts.add(con);
}
System.debug('Contacts Lists:'+accContacts);
if((accId!=null)||(accContacts!=null))
{
for(Contact cx:accContacts)
{
wrapConItems.add(new WrapperAccounts(false,cx));
}
}
}
//method to fetch contact's detail page
public Set<Id> conId=new Set<Id>();
public void fetchConRecords()
{
for(WrapperAccounts contwraps : wrapConItems)
{
if(contwraps.conSel==true)
{
conId.add(contwraps.contLists.Id);
}
System.debug('Selected Contacts:'+contwraps);
}
List<Contact> conx2=[Select Id from Contact WHERE Id IN:conId];
System.debug('Contacts Lists in conx2:'+conx2);
}
//Wrapper Class
public class WrapperAccounts
{
public boolean selected{set;get;}
public Account accList{set;get;}
public Contact contLists{set;get;}
public boolean conSel{set;get;}
public WrapperAccounts(Boolean sel,Account acc)
{
this.accList=acc;
this.selected=sel;
}
public WrapperAccounts(Boolean selec,Contact co)
{
this.conSel=selec;
this.contLists=co;
}
}
}
This will help your requirement.If you have any doubt kindly ask me.
Kindly let me know will it works!
Thanks
Jenefa,Kamala,Saroja
Sweet Potato Tec
I just pasted your code it's working but i am not getting the contact detail in the 3rd block when i click on the contact checkbox.
Try this one
<apex:page controller="AccountWrapper" sidebar="false">
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons >
<!--<apex:commandButton value="Select" action="{!fetchRecords}" reRender="block2" rerender="block3"/>-->
</apex:pageBlockButtons>
<apex:pageBlockSection title="Accounts" columns="3">
<apex:pageBlockTable value="{!wrapItems}" var="c" id="table">
<apex:column headerValue="Select">
<apex:inputCheckbox value="{!c.selected}"/>
<apex:actionSupport event="onclick" action="{!fetch}"/>
</apex:column>
<apex:column value="{!c.accList.Name}" headerValue="Account Name"/>
</apex:pageBlockTable>
<apex:pageBlockTable value="{!wrapConItems}" var="c1" id="block2">
<apex:column headerValue="Select">
<apex:inputCheckbox value="{!c1.conSel}"/>
<apex:actionSupport event="onclick" action="{!fetchCont}"/>
</apex:column>
<apex:column value="{!c1.contLists.Name}" headerValue="Related Contacts Name"/>
</apex:pageBlockTable>
<apex:pageBlockTable value="{!conx2}" var="d1" id="DetailPageBlock">
<apex:column value="{!d1.Name} {!d1.Phone}" headerValue="Contact Detail Page"/>
<!--<apex:detail id=""/>-->
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Create Apex method 'AccountWrapper.getConx2'
<apex:column value="{!d1.Name} {!d1.Phone}" headerValue="Contact Detail Page"/>
I just made the conx2 getter setter and defined the FirstName and Phone in the query but still i am not getting the contact name or anything else. Also i dont want name of contact i want the detail page.
Remove
List<Contact> conx2=[Select Id from Contact WHERE Id IN:conId];
as
conx2=[Select Id from Contact WHERE Id IN:conId];
not sure but the line is 126 in Apex class
Thanks.
this is my updated code:
But still m nt getting detail page of the selected contact.
Now only We understand your requirement clearly.
We are working on this and get back you to after solved.
May I know that the contact detail page to shown in the third section or in another page.
Thanks.
Hey I get back to ASAP.
Thanks.
Will you please send me the updated code?
Thanks.
Thanks for marking as the best answer am trying for the related list to shown get back to as soon as possible.
Thanks,
K.Kamala,Jenefa
Try this one
<apex:relatedList list="Opportunities" />
<apex:relatedList list="Contacts">
<apex:facet name="header">Titles can be overriden with facets</apex:facet>
</apex:relatedList>
<apex:relatedList list="Cases" title="Or you can keep the image, but change the text" />
Thanks,
K.Kamala,Saroja