You need to sign in to do that
Don't have an account?

System.QueryException: Non-selective query against large object type (more than 200000 rows)
Hi guys,
I'm having troubles with this error when i try to do the following query inside a trigger.
public static Map<String, AggregateResult> getTotalDesembolsos(Set<Integer> setAnios, Set<Id> setEjecutivoIds) {
System.debug('\n\n-=#=-\n>>>>>>>>>> ' + 'CRM_DesembolsoTriggerHandler_cls - getTotalDesembolsos' + ' <<<<<<<<<<\n' +
'setAnios' + ': ' + setAnios + '\n' +
'setEjecutivoIds' + ': ' + setEjecutivoIds + '\n-=#=-\n');
Map<String, AggregateResult> mapCantidadDesembolsos = new Map<String, AggregateResult>();
for(AggregateResult objAggregateResultsDesembolsos : [SELECT CALENDAR_YEAR(CRM_FechaInicio__c) Anio
,CRM_EjecutivoComercial__c Ejecutivo
,COUNT(Id) Desembolsos
,COUNT_DISTINCT(CRM_Cliente__c) Clientes
,SUM(CRM_DesembolsoTotalReexpresado__c) TotalDesembolsos
FROM CRM_Desembolso__c
WHERE CALENDAR_YEAR(CRM_FechaInicio__c) IN: setAnios
AND CRM_EjecutivoComercial__c IN: setEjecutivoIds
AND CRM_Cliente__c != NULL
GROUP BY CALENDAR_YEAR(CRM_FechaInicio__c)
,CRM_EjecutivoComercial__c
ORDER BY CALENDAR_YEAR(CRM_FechaInicio__c)
,CRM_EjecutivoComercial__c]) {
System.debug('\n\n-=#=-\n' + 'objAggregateResultsDesembolsos' + ': ' + objAggregateResultsDesembolsos + '\n-=#=-\n');
mapCantidadDesembolsos.put((Integer)objAggregateResultsDesembolsos.get('Anio') + '-' + (String)objAggregateResultsDesembolsos.get('Ejecutivo'), objAggregateResultsDesembolsos);
}
I read someting about Custom Index but I don't know how request this custom index. If someone know something i will appreciate.
Thanks
I'm having troubles with this error when i try to do the following query inside a trigger.
public static Map<String, AggregateResult> getTotalDesembolsos(Set<Integer> setAnios, Set<Id> setEjecutivoIds) {
System.debug('\n\n-=#=-\n>>>>>>>>>> ' + 'CRM_DesembolsoTriggerHandler_cls - getTotalDesembolsos' + ' <<<<<<<<<<\n' +
'setAnios' + ': ' + setAnios + '\n' +
'setEjecutivoIds' + ': ' + setEjecutivoIds + '\n-=#=-\n');
Map<String, AggregateResult> mapCantidadDesembolsos = new Map<String, AggregateResult>();
for(AggregateResult objAggregateResultsDesembolsos : [SELECT CALENDAR_YEAR(CRM_FechaInicio__c) Anio
,CRM_EjecutivoComercial__c Ejecutivo
,COUNT(Id) Desembolsos
,COUNT_DISTINCT(CRM_Cliente__c) Clientes
,SUM(CRM_DesembolsoTotalReexpresado__c) TotalDesembolsos
FROM CRM_Desembolso__c
WHERE CALENDAR_YEAR(CRM_FechaInicio__c) IN: setAnios
AND CRM_EjecutivoComercial__c IN: setEjecutivoIds
AND CRM_Cliente__c != NULL
GROUP BY CALENDAR_YEAR(CRM_FechaInicio__c)
,CRM_EjecutivoComercial__c
ORDER BY CALENDAR_YEAR(CRM_FechaInicio__c)
,CRM_EjecutivoComercial__c]) {
System.debug('\n\n-=#=-\n' + 'objAggregateResultsDesembolsos' + ': ' + objAggregateResultsDesembolsos + '\n-=#=-\n');
mapCantidadDesembolsos.put((Integer)objAggregateResultsDesembolsos.get('Anio') + '-' + (String)objAggregateResultsDesembolsos.get('Ejecutivo'), objAggregateResultsDesembolsos);
}
I read someting about Custom Index but I don't know how request this custom index. If someone know something i will appreciate.
Thanks
Also, refer the below
https://help.salesforce.com/articleView?id=000002493&type=1
Regards,
Amit Singh
Please see the below help reference. It will help you to resolve this issue.
https://help.salesforce.com/articleView?id=000006007&type=1
Make sure and remember the below notes when using Aggregate Query,
Queries that include aggregate functions are subject to the same governor limits as other SOQL queries for the total number of records returned. This limit includes any records included in the aggregation, not just the number of rows returned by the query. If you encounter this limit, you should add a condition to the WHERE clause to reduce the amount of records processed by the query.
Custom index request reference URL with steps,
https://help.salesforce.com/articleView?id=Checklist-for-Custom-Index-Requests&type=1&language=en_US