-
-
Save eddywebs/a1ac7b79fd7f9af6d261 to your computer and use it in GitHub Desktop.
Example of using JSON serialization to pass complex objects to @future handlers in Apex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Example of using JSON serialization to pass complex objects to @future handlers in Apex | |
* $author: [email protected] | |
*/ | |
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); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Sample encapsulated class | |
* $author: [email protected] | |
*/ | |
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