Skip to content

Instantly share code, notes, and snippets.

@quintonwall
Created June 17, 2013 17:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save quintonwall/5798506 to your computer and use it in GitHub Desktop.
Save quintonwall/5798506 to your computer and use it in GitHub Desktop.
Example of using JSON serialization to pass complex objects to @future handlers in Apex
/**
* Example of using JSON serialization to pass complex objects to @future handlers in Apex
* $author: qwall@salesforce.com
*/
public with sharing class AddressFuture {
public AddressFuture () {
List<String> addresses = new List<String>();
AddressHelper ah1 = new AddressHelper('1 here st', 'San Francisco', 'CA', '94105');
AddressHelper ah2 = new AddressHelper('2 here st', 'San Francisco', 'CA', '94105');
AddressHelper ah3 = new AddressHelper('3 here st', 'San Francisco', 'CA', '94105');
//serialize my objects
addresses.add(JSON.serialize(ah3));
addresses.add(JSON.serialize(ah2));
addresses.add(JSON.serialize(ah3));
doFutureCall(addresses);
}
@future
static void doFutureCall(List<String> addressesSer) {
AddressHelper currAddress = null;
for (String ser : addressesSer)
{
currAddress = (AddressHelper) JSON.deserialize(ser, AddressHelper.class);
System.debug('Deserialized in future:'+currAddress.street);
}
}
}
/**
* Sample encapsulated class
* $author: qwall@salesforce.com
*/
public with sharing class AddressHelper {
public String street {set; get;}
public String city {set; get;}
public String state {set; get;}
public String zip {set; get;}
public AddressHelper(String s, String c, String st, String z) {
street = s;
city = c;
state = st;
zip = z;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment