I've created this function with @ReadOnly in a Visualforce that is Working fine (1.000.000 records limit):
@readonly webservice static List<BI_BR_Atendimento_Comercial_e_Carteira__c> getAtendimentoComercial(String lValor,String lAcaoCarteira, String cModAtuacao, Integer climitSize, Integer cOffSet )
{
//Retorno dos proprietários para Atendimento Comercial e Carteira
String query = QUERY_PARCEIROS;
if (lAcaoCarteira == 'Cód. Cliente')
query += ' WHERE BI_BR_Cliente__r.BI_CAM_Codigo_del_cliente__c = :lValor';
if (lAcaoCarteira == 'CNPJ/CPF')
query += ' WHERE BI_BR_Cliente__c = :lValor';
if (lAcaoCarteira == 'Cód. Grupo')
query += ' WHERE BI_BR_Cliente__r.Codigo_Grupo__c = :lValor ';
query += ' AND BI_BR_Adabas__r.BI_BR_Parceiro__c != null AND BI_BR_Excluir__c = false AND BI_BR_Adabas__r.Modelo_de_Atuacao__c = :cModAtuacao ';
query += ' LIMIT :climitSize OFFSET :cOffSet ';
return Database.query(query);
}
And I must Aggregate the results (multiple equal results), but when I do that, my limit comes down to 50.000 again:
@ReadOnly webservice static List<AggregateResult> getAtendimentoComercial(String lValor,String lAcaoCarteira, String cModAtuacao, Integer climitSize, Integer cOffSet )
{
//Retorno dos proprietários para Atendimento Comercial e Carteira
String query = QUERY_PARCEIROS;
if (lAcaoCarteira == 'Cód. Cliente')
query += ' WHERE BI_BR_Cliente__r.BI_CAM_Codigo_del_cliente__c = :lValor';
if (lAcaoCarteira == 'CNPJ/CPF')
query += ' WHERE BI_BR_Cliente__c = :lValor';
if (lAcaoCarteira == 'Cód. Grupo')
query += ' WHERE BI_BR_Cliente__r.Codigo_Grupo__c = :lValor ';
query += ' AND BI_BR_Adabas__r.BI_BR_Parceiro__c != null AND BI_BR_Excluir__c = false AND BI_BR_Adabas__r.Modelo_de_Atuacao__c = :cModAtuacao ';
query += ' GROUP BY BI_BR_Adabas__c, BI_BR_Adabas__r.BI_BR_Parceiro__c, BI_BR_Adabas__r.BI_BR_Parceiro__r.Name, BI_BR_Adabas__r.Name, BI_BR_Adabas__r.Segmento_do_Adabas__c, BI_BR_Adabas__r.Modelo_de_Atuacao__c , BI_BR_Adabas__r.Perfil_de_Atuacao_do_Adabas__c , BI_BR_Adabas__r.Regional_de_Vendas_do_Adabas__c , BI_BR_Cliente__r.BI_No_Identificador_fiscal__c , BI_BR_Cliente__r.Name ,BI_BR_Cliente__r.BI_Denominacion_comercial__c ,BI_BR_Cliente__r.Segmento_do_Cliente__c ,BI_BR_Cliente__r.Subsegmento_do_Cliente__c ,BI_BR_Cliente__r.Segmento_valor__c ,BI_BR_Cliente__r.Atendimento_valor__c ,BI_BR_Cliente__r.Canal__c ,BI_BR_Cliente__r.BillingCity ,BI_BR_Cliente__r.BillingState ,BI_BR_Cliente__r.Tipo_Empresa__c ,BI_BR_Cliente__r.BI_CAM_Codigo_del_cliente__c ,BI_BR_Cliente__r.Codigo_Grupo__c ,BI_BR_Cliente__r.Parent.BI_No_Identificador_fiscal__c ,BI_BR_Cliente__r.Parent.BI_Denominacion_comercial__c ,BI_BR_Cliente__r.BI_BR_Atividade_Economica__c ,BI_BR_Cliente__r.Faixa_de_faturamento__c ,BI_BR_Cliente__r.Data_de_inclus_o__c ,BI_BR_Cliente__r.NE__Status__c ';
query += ' LIMIT :climitSize OFFSET :cOffSet ';
return Database.query(query);
}
It is returning exactly as I expect (1.200 records instead of 47.000), but I need my limit to 1.000.000!
I can't use readOnly='true' on Visualforce because I must make DML of another object.