You need to sign in to do that
Don't have an account?
RarLopz
Too many Query Rows - Developer Console
Can someone please assist, how do i get around this exception of 'Too many query Rows 5001'
list<Id> accId = new list<Id>(); list<Contact> conDSA = [Select Id, Name, DSA__c, AccountID from Contact Where DSA__c = true AND AccountID!=null ]; system.debug('Number of Contacts that are DSA ' +conDSA.size()); for (Contact c: conDSA){ system.debug('>>> ' +c.Name + c.AccountId); accId.add(c.AccountId); } list<AccountContactRelation> acr = [SELECT Id, isDSA__c,AccountId, ContactId FROM AccountContactRelation Where AccountId IN :accId ]; system.debug('Number of records in ACR are: ' +acr.size()); for (AccountContactRelation a: acr){ a.isDSA__c = true; } update acr;
https://help.salesforce.com/articleView?id=000181404&language=en_US&type=1
All Answers
Please check your debug log file of this class, or you can post it here! Because my problem is same as your, hope I can help!
Sorry for this issue you are facing.
The exception is being thrown because the maximum number of rows you can return in SOQL calls in Apex is 50000.
The two SOQL calls you have above are not filtering, I.E., they do not have a LIMIT clause which could prevent this exception.
In your VF Page, you could try to limit this to the number of records.
It looks like your org has an extensive amount of data, so think about the use case. Even if you could display 50,000 products on a page, who is going to be able to read that?
If you add Where and Limit clauses to your SOQL, you'll be able to resolve the error.
Hope this helps.
KIndly mark this as solved if the reply was helpful.
Thanks,
Nagendra
https://help.salesforce.com/articleView?id=000181404&language=en_US&type=1
I don'nt want to set limit to the query because i will then have to run this query 16 times to update all the 80k records
I plan to put my logic in a batch class and then execute the batch from dev console.
This is what i did .
Select Id, Name, DSA__c, AccountID FROM Contact WHERE DSA__c = false AND AccountID!=Null AND EMAIL!=Null
you can follow below code steps :-
if you found this useful then, PLEASE MARK AS A BEST ANSWER!!
Regards
Mukesh
Can you please tell me - since this is generic class, how would i write a test class for this class. ?
@RajVakati, Thanks for your response '
i guess you need toadd false in where conditionSelect Id, Name, DSA__c, AccountID FROM Contact WHERE
DSA__c = falseAND AccountID!=Null AND EMAIL!=Null'Basically I am copying the value of DSA__c from Contact to isDSA__c in AccountContactRelation, thats why my filter is DSA__c = true , and mI am assigning isDSA__ = true.
The exception is being thrown because the maximum number of rows you can return in SOQL calls in Apex is 50000.
The two SOQL calls you have below are not filtering . not have a LIMIT clause which could prevent this exception.
If you add Limit clauses to your SOQL, you'll be able to resolve the error.
list<Id> accId = new list<Id>();
list<Contact> conDSA = [Select Id, Name, DSA__c, AccountID from Contact
Where DSA__c = true AND AccountID!=null Limit 10000];
system.debug('Number of Contacts that are DSA ' +conDSA.size());
for (Contact c: conDSA){
system.debug('>>> ' +c.Name + c.AccountId);
accId.add(c.AccountId);
}
list<AccountContactRelation> acr = [SELECT Id, isDSA__c,AccountId, ContactId
FROM AccountContactRelation
Where AccountId IN :accId limit 10000 ];
system.debug('Number of records in ACR are: ' +acr.size());
for (AccountContactRelation a: acr){
a.isDSA__c = true;
}
update acr;
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi