I have a problem executing a batch in some limit cases that i want to cover to avoid future concerns. The scenario is the following: My batch works on n(reasonable high number) records of the same SObject, initially i scheduled this batch to start with 2000 (the maximum number Salesforce provides for non-iterator BC) records per batch. Basically this job evaluate each record at the start and if it doesn't meet some conditions the record is discarded and so on. The limit case that lead me here is this, if inside the 2000 records permitted I have more than the 80% of records evaluated as true I received the "Too much query rows" (10k+1) alert, so we must keep the limit under 80% of 2000 to avoid this problem but my question is, can I retrieve some values around apex libraries in which I can check when the limit is near to the edge?
In particular the fact that the value 10k+1 is shown means that it is stored somewhere. Is it accessible?(if yes, the following request is unuseful) I cannot find that value in documentation, since counting any single DML is unthinkable is possible to calcutale dinamically the maximum number of records that can be processed avoiding the error but withound the value that I previously requested?