+ Start a Discussion
sfdc-Lsfdc-L 

forloop cause

Hi all, i dont want to write a soql query in forloop because it bypass the governor limits .so how can i write the soql outside of the forloop.so kindly let me know asap. String[] ps= new String[]{}; public String[] getUserLicense() { return ps; } public void setUserLicense(String[] ps) { this.ps = ps; } public List getItems() { List op = new List(); for(UserLicense p : [SELECT Id, Name FROM UserLicense]) op.add(new SelectOption(p.Id, p.Name)); return op; } == vf: THanks
MarrisMarris

Hi 

 

Use List, which fetches max of 1000 values in a single line of query. 

 

String[] ps= new String[]{}; 
List<UserLicense> objUL = [SELECT Id, Name FROM UserLicense];
public String[] getUserLicense() 
{ 
return ps; 
} 
public void setUserLicense(String[] ps) { 
this.ps = ps; 
} 
public List getItems() { 
List op = new List(); 
for(UserLicense p : objUL) {
op.add(new SelectOption(p.Id, p.Name)); 
return op; 
}

It solves your problem,Then mark it as solution 

 

Thanks

 Marris