Skip to main content
cao wenjie a posé une question dans #Apex
hi

I have a apex batch:

  global Iterable<AggregateResult> start(Database.BatchableContext bc) {

    AggregateResult[] sg= [SELECT Phone FROM Account WHERE Phone <> null GROUP BY Phone HAVING COUNT(Phone) >= 2];

    return sg;

  }

but it doesnt working.The error is:

09:39:03.0 (22546931)|SOQL_EXECUTE_BEGIN|[32]|Aggregations:0|SELECT Phone FRO Account WHERE Phone != NULL GROUP BY Phone HAVING COUNT(Phone) >= 2

09:39:03.0 (570162894)|SOQL_EXECUTE_END|[32]|Rows:44

09:39:03.0 (570212289)|EXCEPTION_THROWN|[32]|System.LimitException: Too many query rows: 50001

09:39:03.0 (570386384)|HEAP_ALLOCATE|[32]|Bytes:30

09:39:03.0 (570430741)|SYSTEM_MODE_EXIT|false 09:39:03.0 (570514055)|FATAL_ERROR|System.LimitException: Too many query rows: 50001

i dont know why the error is happen.

(there is no error by using Name field

× System.LimitException: Too many query rows: 50001

AggregateResult[] sg= [SELECT Phone FROM Account WHERE Phone <> null GROUP BY Phone HAVING COUNT(Phone) >= 2];

○ No error

AggregateResult[] sg= [SELECT Name FROM Account WHERE Name <> null GROUP BY Name HAVING COUNT(Name) >= 2];

)

Is there a way to solve this?

 
1 réponse
  1. 17 mai 2016, 04:44

    Hi,

    • You can use the Database.executeBatch(sObject className, Integer scopeSize) method to set the batch size.
    • Used Limit and WHERE CLAUSES
    • Also, since you are writing Batch Code, you can also try reducing your scope. The standard batch size is 200 records, but you can increase this up to 2,000 or reduce it to, say, 50. If you are querying a lot of records in the Execute method, it might help to reduce the batch size so the total ⌗ records queried per batch is < 50,000.

    Hope this helps you!

    Best Regards,

    Jyothsna
0/9000