Skip to main content

The SObjects passed to them might change, whether it is a future method or Queueable APEX. So why Queueable Apex accepts SObjects as a parameter but the #Future method does not?

 

#Salesforce #Salesforce Developer#Queueable Apex#Asynchronous Apex

2 answers
  1. Jan 15, 2024, 10:50 AM

    HI @Amit mishra

     

    please check the below one:

    • https://www.linkedin.com/pulse/explanation-why-queueable-apex-accepts-sobjects-parameters-gupta-vbmaf 
    • https://trailhead.salesforce.com/trailblazer-community/feed/0D54V00007T4GRxSAN
    • Queueable Apex is more flexible and capable of handling complex, stateful asynchronous processes, hence it allows SObjects as parameters.
    • Future methods are designed for simpler, stateless asynchronous processes and thus require parameters to be serializable, limiting them to primitive data types.
    • Future Method: If you pass an SObject to a future method (which you can't directly), any changes made to that record after the method call but before its execution won't be reflected in the future method's execution. Future methods are better suited for scenarios where you're dealing with immutable data, like IDs or other primitives.
    • Queueable Apex: When you pass an SObject to a Queueable job, you're effectively creating a snapshot of that object at the time of the job's initiation. If the record changes in the database after enqueuing but before execution, those changes will not be reflected in the job. However, the Queueable job has the flexibility to re-query the database to get the latest state if needed.
0/9000