function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ 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