2

Can we get job id or job name from current running job? For example:

global class MySchedule implements Schedulable {
    global void execute(SchedulableContext sc) {

        Id jobId = sc.getJobId();
        String jobName = sc.getJobName();
    }
}

Is there any workaround to get the current job id or job name ?

6

Yes. If you call getTriggerId() on your SchedulableContext, it will provide the Id of your CronTrigger, and thence the CronJobDetail for this Schedulable.

From there, you can do

CronTrigger ct = [SELECT CronJobDetail.Name FROM CronTrigger WHERE Id = :myId];

and that'll give you the name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.