function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SFDC New UserSFDC New User 

Apex Queue Data sync

Hi,

The apex queue submitted thru @future job, when it being processed, does it query the real time data from the object to process or using the data value as at the queue submitted time?

E.g.

At 01:00am, Trigger on account submitted a record A : Name = Apple, -- still pending in the queue for process (job 1)

At 01:05am, Record A, Name changed to : APPLE -- job 1 still in pending queue, job 2 is queued

At 01:10am, job 1 is finally processed, does it take Apple or APPLE for processing?

Anyone know?

Thank you.
Best Answer chosen by ShashForce
ShashForceShashForce
Hi,

As per the queueing model in Salesforce, it should take APPLE, as you get the latest data when the job is run in the future. You should usually choose to use future methods only when the result of the method does not get affected by these kind of dependencies.

If this answers your question, please mark this as the Best Answer for this post, so that others can benefit from this post.

Thanks,
Shashank

All Answers

ShashForceShashForce
Hi,

As per the queueing model in Salesforce, it should take APPLE, as you get the latest data when the job is run in the future. You should usually choose to use future methods only when the result of the method does not get affected by these kind of dependencies.

If this answers your question, please mark this as the Best Answer for this post, so that others can benefit from this post.

Thanks,
Shashank
This was selected as the best answer
Mikola SenykMikola Senyk
Apex job with @future annotation will be run in different execution context. As you know data will be committed into database after end of execution context.
If @future method is called from trigger we will have the following steps:
  start trigger execution context
At 01:00am, Trigger on account submitted a record A : Name = Apple , run @future (job 1)
  stop trigger execution context (Name = Apple is committed)
  start execution context of job 1
  start execution context of job 2
At 01:05am, Record A, Name changed to : APPLE
  stop execution context of job 2 (Name = APPLE)
At 01:10am, job 1 Name equals to APPLE
  stop execution context of job 1