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
ashok chandraashok chandra 

Issue System.LimitException : Too many query rows : 50001(very very urgent)

I have 45,000 Records in Transaction Object.

I am running two 'group by' queries on Transaction Object.
Follwing are the queries.

Aggregations:0|select max(id) id1, Max(CnP_PaaS__CnP_Account_ID__c) ClickAndPledgeAccountName,Max(CnP_PaaS__CnPAccountID__c) ClickAndPledgeAccountId,Max(CnP_PaaS__Contact__r.Email) ContactEmail,CnP_PaaS__Contact__r.Name ContactName from CnP_PaaS__CnP_Transaction__c where id!=null and (CnP_PaaS__Application_Name__c=:appname or CnP_PaaS__Application_Name__c=null) and CnP_PaaS__TransactionTimeZone__c != Null Group by CnP_PaaS__Contact__r.Name


Rows:1256


Aggregations:0|select max(id) id1, Max(CnP_PaaS__CnP_Account_ID__c) ClickAndPledgeAccountName,Max(CnP_PaaS__CnPAccountID__c) ClickAndPledgeAccountId,Max(CnP_PaaS__Contact__r.Email) ContactEmail,CnP_PaaS__Contact__r.Name ContactName from CnP_PaaS__CnP_Transaction__c where id!=null and (CnP_PaaS__Application_Name__c=:appname or CnP_PaaS__Application_Name__c=null) and CnP_PaaS__TransactionTimeZone__c != Null Group by CnP_PaaS__Contact__r.Name limit 400


Rows:400

when i am running these queries i am getting an exception.

"Too many query rows: 50001"

So, What is the solution for this.

hanimihanimi

hi,

 

Use Limit 

 

for example:

 

Public static  integer getTotalVotes()

   {

        integer totalIdea = [SELECT count() FROM Vote where Parent.Type='Idea' limit 501

];

        return totalIdea ;

   }

ashok chandraashok chandra

I am using LIMIT in My soql Query.

 

  still I am getting that.

 

 

Thanks for Respnse

kiranmutturukiranmutturu

see those queries block going in to an infinite block ....may be the same class or method is invoking multiple times in the same process 

ashok chandraashok chandra

Thanks for ur reply,

 

  I Have a confusion on soql  query with group by option.

 

How will the soql query run on the database.

  

 I have 197,595 records on contact object. 

 

i am running this query like 'select name from contact where name!='' group by name limit 10000 

 

it is returning 10,000

 

but in limits it is showing  Number of query rows: 19234 out of 50000

 

y it is giving 19234

 

kiranmutturukiranmutturu

r u using dynamic soql if not can you please try 

select name from contact where name!= null and check

ashok chandraashok chandra

hi kiran,

 

   Yes i am building dynamic soql. The requirement is that. i really don't know why it is returning all the records. plz explain me if u have any idea

 

 

Thanks

Jeff MayJeff May

One thing I noticed a while ago is that it is likely not returning all the rows.  When you use dynamic SOQL, SFDC looks at the query and decides whether it "could" return too many records.  If if "could" return too many, you get the error.  The determination is based on whether the SOQL query is "selective"  Here is an entry page on the topic: http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_SOQL_VLSQ.htm

 

Success,

 

JeffM

Hengky IlawanHengky Ilawan

Hi,

 

If you use Group By in your query, you actually select the distinct name from your contact object.

 

And the reason query rows showed a different number than what you've specified at your LIMIT keyword was because the query rows counted any records that were included in the aggregation, not just the number of rows returned by the query.

 

Could you give us a bit of background of your query, and maybe some codes as well so we can take a look?

 

-Hengky-