You need to sign in to do that
Don't have an account?
Rico Rivera
Cannot access CronTriggerId from AsyncApexJob metadata
Trying to query what ApexClass was used by a CronTrigger by determining what Trigger executed an AsyncApexJob.
The AsyncApexJob shows the Apex Class and if I can query the CronTriggerId that executed that job, I can determine what job was using that Apex Class.
The SOAP API Developer Guide shows that the Metadata for AsyncApexJob has a field for CronTriggerId but when I attempted to query that info, I received an error that the column doesn't exist for CronTriggerId.
I know exactly what you mean, quite annoying. Works fine and yields results when executed from the query editor in DevConsole.
However, when executed from an Apex class, it yields a compile error.
(No such column 'CronTriggerId' on entity 'AsyncApexJob')
I found a related idea (https://ideas.salesforce.com/s/idea/a0B8W00000GdgQhUAJ/add-a-relationship-field-between-crontrigger-and-asyncapexjob), feel free to upvote it...
All Answers
please find the below query where you can find required information..
SELECT id,CronJobDetailId,NextFireTime,PreviousFireTime,state,StartTime,EndTime,CronExpression,TimesTriggered,TimezoneSidKey FROM CronTrigger
SELECT id,CreatedDate,CreatedById,JobType,ApexClassId,Status,JobItemsProcessed,TotalJobItems,NumberOfErrors,CompletedDate,MethodName,ExtendedStatus,ParentJobId,LastProcessed,LastProcessedOffset FROM AsyncApexJob
If it was helpful.,
Please Mark it as Best Answer.
Thanks,
Prasanthi
Hey Prasanthi,
Thanks for the response but that's not what I'm looking for.
Essentially I want to be able to determine what Apex Class a CronTrigger is running.
I'd be able to determine what ApexClass a CronTrigger was running if there was a relationship between the AsyncApexJob and CronTrigger object. When looking it up, there's supposed to be a field called "CronTriggerId" on the AsyncApexJob object but I can't retrieve values from that field when I attempt to query and I get an error that says that field doesn't exist for the AsynApexJob object.
please check this if it can help..
select ApexClass.Name, ApexClass.Namespaceprefix, Id, JobItemsProcessed, JobType, Status, NumberOfErrors, MethodName from AsyncApexJob
Use WHERE clause also to find on particular JOB.
Please mark it as Best answer if youu find useful.
Thanks,
Prasanthi
Hey Prasanthi,
That also doesn't tell me what CronTrigger was used to execute that Job.
To give you some more background, I tried to deactivate a Trigger that was firing a Job because it was running as an inactive user. The Trigger was poorly named to "Job2". When the error message came in through my email, it gave me the Job id and from that I was able to determine the Apex Class.
I was pretty sure it was the Trigger labelled "Job2" but I could not confirm what Apex Class Job2 was using because I couldn't not manage the Trigger from the "Scheduled Jobs" screen and I could not confirm from the Job what Trigger had executed it to run in the first place.
Thanks,
Rico Rivera
We can also check directly in SETUP --> QFB --> APEX Flex Queue
Thanks,
Prasanthi
Cron trigger is related to schedule job.
AsyncApexJob is related to asynchronous jobs...
Thank You,
Prasanthi
I'm trying to find a relation between CronTrigger and AsyncApexJob via SOQL. I know they are directly related because the trigger creates the AsyncApexJob but there's nothing I can query to show what trigger fired what job. Looking at the SOAP API developer guide, there should be a field to query on the AsyncApexJob carried CronTriggerId but I cannot query that info.
I know exactly what you mean, quite annoying. Works fine and yields results when executed from the query editor in DevConsole.
However, when executed from an Apex class, it yields a compile error.
(No such column 'CronTriggerId' on entity 'AsyncApexJob')
I found a related idea (https://ideas.salesforce.com/s/idea/a0B8W00000GdgQhUAJ/add-a-relationship-field-between-crontrigger-and-asyncapexjob), feel free to upvote it...
Thanks Ronald,
Definitely not optimal but a solution I hadn't realized. I'll do that for future queries where I run into a similiar issue.
Luckily I don't need to perform that Query in a class currently, I was attempting to audit our automations and couldn't accurately do so. I was using a third party chrome extension called Salesforce Inspector rather than the Dev Console.