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
Dhilip DussaDhilip Dussa 

Add two queries in one loop?

Hi,

I have to two loop values in one loop how it is possible?

Ex:

List<Account> accList = [SELECT Id, Name FROM Account LIMIT 10];
List<Account> accList2 = [SELECT Id, Name FROM Account LIMIT 9 OFFSET 1];

for(){
String s = accList.name  + accList2.Name;
}

i want to pass in for loop one by one how it will be possible please help me.

Thanks,
Dhilip Dussa

Carolina W 2Carolina W 2
List<Account> accList = [SELECT Id, Name FROM Account LIMIT 10];
List<Account> accList2 = [SELECT Id, Name FROM Account LIMIT 9 OFFSET 1];

for(Interger counter : accList.length){
String s = accList.name[counter]  + accList2.Name[counter];
}
Hi! Try it! 

 
ankit bansalankit bansal
Hi Dhilip,
I am unable to guess what you want to achieve with the above code since 
List<Account> accList = [SELECT Id, Name FROM Account LIMIT 10]; will return the first 10 records
and this List<Account> accList2 = [SELECT Id, Name FROM Account LIMIT 9 OFFSET 1]; will return the last 9 records of the above query. 
If you put any of this in a for loop you might run into null pointer reference exception. Please tell a little bit more about your requirement and then we can help.