Avoid child queries in long running batches.

Recently I was working on a production incident and have found issues with child queries in batch apex where the following stats holds right:

Query: On contact 
Total records: ~0.4 million
Child query filters: Two string and one record type check

Issues:
  • CPU timeout error
  • Batch will not start.

Solution: Removed child query completely and written logic inside execute method. Please follow code snippet given below:







Comments