I need to create a summaries record for each result generated by the following query, which returns around 12K.
The trouble is the aggregate result has to query 600K records, so I get 'System.LimitException: Too many query rows: 50001'.
What should be the right strategy here? Generate a list of contract and call out smaller queries for ~12K of them?
Your advice will be appreciated.
List<AggregateResult> queryCurrentYear = [select TI_Contract__c cntr, Line__c line, count(id) recscount, sum(number_of_calls__c) totalcalls, sum(total_costs__c) totalcost, max(ti_contract__r.value__c) value from detailed_call_data__c where (date__c >= :dateStart) and (date__c <= :dateEnd) and ti_contract__c !='' GROUP BY TI_Contract__c, Line__c];