You need to sign in to do that
Don't have an account?
ARUL BERNARD I 6
Too many SOQL queries I am using in wrapper class
Hi Please help me out to solve this problem.
public class wrapperExample{
public List<Wrapper> wrapAccountList {get; set;}
public wrapperExample(){
if(wrapAccountList == null) {
wrapAccountList = new List<Wrapper>();
for(Account a: [select Id, Name,BillingState, Website, Phone from Account limit 100]) {
for(list<contact> r: [select Id, Name from Contact where AccountId = :a.Id]){
wrapAccountList.add(new Wrapper(a,r));
}
}
}
}
public class Wrapper{
public Account acc {get; set;}
public List<Contact> con {get; set;}
public Wrapper(Account a, List<Contact> c) {
acc = a;
con = c;
}
}
}
public class wrapperExample{
public List<Wrapper> wrapAccountList {get; set;}
public wrapperExample(){
if(wrapAccountList == null) {
wrapAccountList = new List<Wrapper>();
for(Account a: [select Id, Name,BillingState, Website, Phone from Account limit 100]) {
for(list<contact> r: [select Id, Name from Contact where AccountId = :a.Id]){
wrapAccountList.add(new Wrapper(a,r));
}
}
}
}
public class Wrapper{
public Account acc {get; set;}
public List<Contact> con {get; set;}
public Wrapper(Account a, List<Contact> c) {
acc = a;
con = c;
}
}
}
your this line for(list<contact> r: [select Id, Name from Contact where AccountId = :a.Id]){
is causing the problem
in this for loop
for(Account a: [select Id, Name,BillingState, Website, Phone from Account limit 100])
add the account ids to a set and use that it in the where clause of
for(list<contact> r: [select Id, Name from Contact where AccountId = :a.Id]){
this should fix it
Please check following snippet code :
Hope this helps you!
If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.
Thanks
Varaprasad
@For Support: varaprasad4sfdc@gmail.com
I need to code without using sub-query