You need to sign in to do that
Don't have an account?

How to get a job id of future call?
Hi,
When we make future calls, a job gets enqueued in asyncapexjob record. Is there any way to get job id of future call which has been currently made?
For example, I have a button on case record, when I click that button, a future method runs and calls other web service. Now, multipe people can click on the button at the same time/or almost near by time so I want to display the status of their job.
Is it possible at all?
Thanks.
When we make future calls, a job gets enqueued in asyncapexjob record. Is there any way to get job id of future call which has been currently made?
For example, I have a button on case record, when I click that button, a future method runs and calls other web service. Now, multipe people can click on the button at the same time/or almost near by time so I want to display the status of their job.
Is it possible at all?
Thanks.
All Answers
Please use AsyncApexjob object with a jobType of future
https://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_asyncapexjob.htm
6 people clicked on the button which invokes future call, so 6 future calls will be made and 6 future jobs will be enqueued.
Now, is it possible to show job status of the future call to their respective user only? I don't want to show all the future job status to all the users.
From the click event of the button... call the following SOQL in the click event to find the future job Id invoked by the currently logged in user
List<AsyncApexJob> futureCalls = [Select Id, CreatedById, CreatedBy.Name, ApexClassId,MethodName,Status from AsyncApexJob where JobType = 'future' and Id=:UserInfo.getUserId() Sort By CreatedDate ASC];
and then loop through 'futureCalls' to pick up the Job Id of the latest future call invoked by the current user'
Cheers