I am trying to set a scheduled Apex job to run daily at 1AM. Records are not being inserted as I believe they should be. I imagine there is are errors occurring during execution of the class. I have a bunch of System.Debug statements to write errors that occur. I unfortunately do not see any debug logs listed on Setup -> Monitoring -> Debug Logs. All I see is User Trace Flags and an empty list under Debug Logs.
2 Answers
Debug logs are not running all the time, there is a limit of 20 logs captured per trace set up.
- Schedule the trace to start right before your batch scheduled time
- If the user is active in the system however this could consume the 20 logs before the batch is run
If your batch has a lot of 'chunks' you could consume the 20 logs before the error has occurred.
You best bet is to manually run the batch and monitor it via the dev console.
This solved it for me,
After scheduling your apex class either by using dev console
and execute anonymous
, or by using the UI,
- Go to
setup -> scheduled
jobs and check theSubmitted by
the field for the specific scheduled job, this user name is important - Go to
setup -> debug logs
and click onnew
trace entity type
must be usertrace entity name
must be the same user as you saw in thesubmitted by
field- Get your start and end time correct (make sure they overlap the time when your scheduled class will run)
- Select your
debug level
by referring to the official documentation in the Trailblazer Community or complete this Trailhead module
Submitted By
user for the job should be same asName
field in the debug log. Check if it is causing the issue?Traced Entity Type
should be User and theTraced Entity Name
should be same user as that ofSubmitted By
for the job.