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 ?

1 Answer 1

7

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .