You need to sign in to do that
Don't have an account?
mahesh padigela 1
VisualForce page using wrapper classes
Hi,
I am newbie to salesforce, I am trying to design a visualforce page, which contains a checkbox and list of account details. when the required accounts are checked and custom button is clicked i wanted to display the details of accounts and contact details on the right side of the page.
I am unable to acheieve it. Below is my code.
Please help me,Thanks in Advance.
I am newbie to salesforce, I am trying to design a visualforce page, which contains a checkbox and list of account details. when the required accounts are checked and custom button is clicked i wanted to display the details of accounts and contact details on the right side of the page.
I am unable to acheieve it. Below is my code.
Please help me,Thanks in Advance.
public class accountcontactwrap { public list<accountwrap> warpacc{get;set;} public list<account> selectedAccounts{get;set;} public list<contact> cont{get;set;} public list<contactwrap> wrapcon{get;set;} public accountcontactwrap(){ warpacc=new list<accountwrap>(); for(account ab:[select id,name,phone from account limit 10]){ warpacc.add(new accountwrap(ab)); } } public void showcontacts(){ cont=new list<contact>(); for(accountwrap warpobj:warpacc) { if(warpobj.isSelected==true){ cont=[select lastname from contact where accountid=:warpobj.acc.id]; wrapcon.add(new contactwrap(warpobj,cont)); } } } public class accountwrap{ public account acc{get;set;} public boolean isSelected{get;set;} public accountwrap(account a){ acc=a; isSelected=false; } } public class contactwrap{ public accountwrap accw{get;set;} public list<contact> conwrap{get;set;} public contactwrap(accountwrap asd,list<contact> ctc){ accw=asd; conwrap=ctc; } } }The VF Code:
<apex:page sidebar="false" controller="accountcontactwrap" > <apex:form > <apex:pageblock > <apex:pageBlockButtons > <apex:commandButton action="{!showcontacts}" value="Show contacts for selected accounts" reRender="block2"/> </apex:pageBlockButtons> <apex:pageBlockSection columns="2"> <apex:pageblockTable value="{!warpacc}" var="wc"> <apex:column > <apex:inputcheckbox /> </apex:column> <apex:column value="{!wc.acc.name}"/> </apex:pageblockTable> <td> <apex:repeat value="{!wrapcon}" var="c" id="block2"> <tr><td> <apex:outputText value="{!c.accw.acc.name}"/></td> <td> <apex:outputText value="{!c.conwrap}"/></td></tr> </apex:repeat> </td> </apex:pageBlockSection> </apex:pageblock> </apex:form> </apex:page>
Greetings to you!
Please try the below code, I have tested in my org and it is working fine. Kindly modify the code as per your requirement.
Visualforce:
Controller:
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
All Answers
Greetings to you!
Please try the below code, I have tested in my org and it is working fine. Kindly modify the code as per your requirement.
Visualforce:
Controller:
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
Thanks , I got the solution.