Why can we not pass Sobjects as an parameter in future calls

I read in salesforce documents that Methods with the future annotation cannot take sObjects or objects as arguments.

Can any one please explain why can we not pass Sobjects as an parameter in future methods?
How does Future methods works behind the scene.

Answer

My understanding is as follows – I can’t remember where I heard/read this though, so caveat emptor:

If you could pass an sObject as a parameter you would send the current record contents (fields) to the future method. As this executes asynchronously, the contents may be stale as field changes could be applied through triggers etc. Therefore the language “encourages” you to pull the latest version of the object from the database by not supporting this directly.

I’d also expect its to cut down on the memory implications of retaining collections of complex objects across transactions.

That said there are workarounds – check out Quinton Wall’s post using JSON serialization/deserialization:

http://blogs.developerforce.com/developer-relations/2013/06/passing-objects-to-future-annotated-methods.html

Attribution
Source : Link , Question Author : Pramod Kumar , Answer Author : Bob Buzzard

Leave a Comment