Skip to content

Instantly share code, notes, and snippets.

@eddywebs
Forked from quintonwall/AddressFuture
Created October 26, 2015 17:18
Show Gist options
  • Select an option

  • Save eddywebs/a1ac7b79fd7f9af6d261 to your computer and use it in GitHub Desktop.

Select an option

Save eddywebs/a1ac7b79fd7f9af6d261 to your computer and use it in GitHub Desktop.

Revisions

  1. quintonwall created this gist Jun 17, 2013.
    35 changes: 35 additions & 0 deletions AddressFuture
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    /**
    * 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);
    }
    }
    }
    22 changes: 22 additions & 0 deletions AddressHelper
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    /**
    * 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;

    }

    }