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
Vivek ViswanathVivek Viswanath 

How do I implement Query more in Apex?.

Hi All,

This is the scenario we are working with and are having an issue looking for a solution.

I am trying to retrieve more than 1000 records in an Apex Query and apparently 1000 is the upper limit to the number of records that can be retrieved.

Dose any one know of a query more in a trigger or how to implement this. 

Below is the query:

for (Lease_Com__c[] leaseCommission :

[select Id, lease_nbr__r.Name, gcp_amt__c, lease_nbr__r.End_User__c, lease_nbr__r.Funded_Dt__c from lease_com__c

where OwnerId = :UserID

and lease_nbr__r.Funded_Dt__c < :dtBeginningOfNextMonth

and lease_nbr__r.Funded_Dt__c >= :dtBeginningOf6MonthsPrevious

order by lease_nbr__r.Funded_Dt__c desc] ) {

}


Vivek Viswanathan


Divya GoelDivya Goel
Hi,
 
There is no need to put query more in apex code or Apex does not have any thing like query more. To access more then 1000 records you have to put your soql query in for loop as you did below
for (Lease_Com__c[] leaseCommission :

[select Id, lease_nbr__r.Name, gcp_amt__c, lease_nbr__r.End_User__c, lease_nbr__r.Funded_Dt__c from lease_com__c ])

this for loop will handel the functionality of queryMore itself.

Thanks,

Divya

Richard CuaRichard Cua
Hi,

Have you been able to get this for loop SOQL Query to work with more than 1000 records? I have tried to run a count of the number of records returned with the following query but still recieve the error saying there are too many rows...

Code:
  integer numTouch3 = 0;
  for (CampaignMember[] cm : [select id from CampaignMember where CampaignId  = :newCampaign[0].id AND LastModifiedDate > :newCampaign[0].Summary_Last_Calculate__c AND Status = 'Solicit - Touch 3']){
   numTouch3 = cm.size();
  }

Would appreciate any advice.