You need to sign in to do that
Don't have an account?
sainath .chalamcherla
wrapper class: For Loop and pgaeblock Table
Hi Team,
This is sainath,I am begginer, I am working on Wrapper class.
Requirements: I have to display account,contact,opportunity fields in pageblock table using wrapper class. i done with code in apex and visualforce page.But there is a issue with data alignment in pageblock table.find attached code below.
visualforce Page:
Output:
All Data Should be in same rows(same alignment).But it is showing in different way.Any body can suggest how to overcome this issue.
Thanks&Regards
sainath
This is sainath,I am begginer, I am working on Wrapper class.
Requirements: I have to display account,contact,opportunity fields in pageblock table using wrapper class. i done with code in apex and visualforce page.But there is a issue with data alignment in pageblock table.find attached code below.
public class mswrapper { public class saiwrapper { public string Accname {get;set;} public string accnum {get;set;} public string confstname {get;set;} public string conlstname {get;set;} public double oppamount {get;set;} public string oppstgname {get;set;} } public list<saiwrapper> wrplst {get;set;} public mswrapper() { wrplst = new list<saiwrapper>(); saiwrapper swrp; for(Account Acclst : [SELECT Name,AccountNumber FROM Account WHERE Type = 'Customer - Direct' LIMIT 10] ) { swrp = new saiwrapper(); swrp.Accname = Acclst.Name; swrp.accnum = Acclst.AccountNumber; wrplst.add(swrp); } for(Contact conlst :[SELECT FirstName,LastName FROM Contact WHERE Level__c = 'Primary' LIMIT 10]) { swrp = new saiwrapper(); swrp.confstname = conlst.FirstName; swrp.conlstname = conlst.LastName; wrplst.add(swrp); } for(Opportunity opplst :[SELECT Amount,StageName FROM Opportunity WHERE Amount < 10000 LIMIT 10]) { swrp = new saiwrapper(); swrp.oppamount = opplst.Amount; swrp.oppstgname = opplst.StageName; wrplst.add(swrp); } } }
visualforce Page:
<apex:page controller="mswrapper"> <apex:pageBlock > <apex:pageBlockTable value="{!wrplst}" var="wrvar"> <apex:column value="{!wrvar.Accname}" headerValue="Account Name" title="Account"/> <apex:column value="{!wrvar.accnum}" headerValue="Account Number" title="Account"/> <apex:column value="{!wrvar.confstname}" headerValue="Contact FirstName" title="Contact"/> <apex:column value="{!wrvar.conlstname}" headerValue="Contact LastName" title="Contact"/> <apex:column value="{!wrvar.oppamount}" headerValue="Amount" title="Opportunity"/> <apex:column value="{!wrvar.oppstgname}" headerValue="StageName" title="Opportunity"/> </apex:pageBlockTable> </apex:pageBlock> </apex:page>
Output:
All Data Should be in same rows(same alignment).But it is showing in different way.Any body can suggest how to overcome this issue.
Thanks&Regards
sainath
Update your controller like this,
There should be some relationship b/w Accounts,Contact and Opportunity recrods.
You queried seperately, there is no relationship b/w all those records.
You can do it with single query and add it to wrapper list. Use follow query.
List<Account> acclist = [select Id, Name, (select Id, FirstName, LastName From Contacts WHERE Level__c = 'Primary' LIMIT 10),(select Amount,StageName FROM Opportunities WHERE Amount < 10000 LIMIT 10) From Account WHERE Type = 'Customer - Direct' LIMIT 10];
Hope it helps you !!