Revisions
-
kevinohara80 revised this gist
Feb 13, 2012 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -134,7 +134,6 @@ public class Async { } return null; } } -
kevinohara80 revised this gist
Feb 13, 2012 . 2 changed files with 3 additions and 119 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -120,6 +120,7 @@ public class Async { } catch (Exception e) { System.debug('Error in SObject List serialization'); } return null; } @@ -131,6 +132,8 @@ public class Async { } catch (Exception e) { System.debug('Error in SObject serialization'); } return null; } This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,119 +0,0 @@ -
kevinohara80 revised this gist
Feb 13, 2012 . 1 changed file with 119 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,119 @@ @isTest private class Async_Test { static List<Lead> leads; static { leads = new List<Lead>(); Lead l1 = new Lead(); l1.FirstName = 'Test1'; l1.LastName = 'TestLast1'; l1.Email = '[email protected]'; l1.Status = 'New'; l1.Company = 'Test Co'; leads.add(l1); Lead l2 = new Lead(); l2.FirstName = 'Test2'; l2.LastName = 'TestLast2'; l2.Email = '[email protected]'; l2.Status = 'New'; l2.Company = 'Test Co'; leads.add(l2); } static testMethod void testInsertList() { Async.insertSObjects(Async.prepare(leads)); } static testMethod void testInsertSingle() { Async.insertSObjects(Async.prepare(leads.get(0))); } static testMethod void testUpdateList() { insert leads; for(Lead l : leads) { l.FirstName = 'NewName'; } Async.updateSObjects(Async.prepare(leads)); } static testMethod void testUpdateSingle() { insert leads; leads.get(0).FirstName = 'NewName'; Async.updateSObjects(Async.prepare(leads.get(0))); } static testMethod void testUpsertList() { insert leads; for(Lead l : leads) { l.FirstName = 'NewName'; } Async.upsertSObjects(Async.prepare(leads)); } static testMethod void testUpsertSingle() { insert leads; leads.get(0).FirstName = 'NewName'; Async.upsertSObjects(Async.prepare(leads.get(0))); } static testMethod void testDeleteList() { insert leads; for(Lead l : leads) { l.FirstName = 'NewName'; } Async.deleteSObjects(Async.prepare(leads)); } static testMethod void testDeleteSingle() { insert leads; leads.get(0).FirstName = 'NewName'; Async.deleteSObjects(Async.prepare(leads.get(0))); } static testMethod void forceSingleInsertFailure() { SObject s; Async.insertSObjects(Async.prepare(s)); } static testMethod void forceListInsertFailure() { List<SObject> s = new List<SObject>(); Async.insertSObjects(Async.prepare(s)); } static testMethod void forceSingleUpdateFailure() { SObject s; Async.updateSObjects(Async.prepare(s)); } static testMethod void forceListUpdateFailure() { List<SObject> s = new List<SObject>(); Async.updateSObjects(Async.prepare(s)); } static testMethod void forceSingleUpsertFailure() { SObject s; Async.upsertSObjects(Async.prepare(s)); } static testMethod void forceListUpsertFailure() { List<SObject> s = new List<SObject>(); Async.upsertSObjects(Async.prepare(s)); } static testMethod void forceSingleDeleteFailure() { SObject s; Async.deleteSObjects(Async.prepare(s)); } static testMethod void forceListDeleteFailure() { List<SObject> s = new List<SObject>(); Async.deleteSObjects(Async.prepare(s)); } } -
kevinohara80 revised this gist
Feb 11, 2012 . 1 changed file with 44 additions and 11 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -13,7 +13,7 @@ public class Async { /***********************/ /* ASYNC DML METHODS */ /***********************/ // insert sobjects @@ -29,9 +29,14 @@ public class Async { } if(!sObjs.isEmpty()) { try { insert sObjs; } catch (Exception e) { System.debug('Error inserting SObjects'); } } } // upsert sobjects @@ -47,9 +52,14 @@ public class Async { } if(!sObjs.isEmpty()) { try { upsert sObjs; } catch (Exception e) { System.debug('Error upserting SObjects'); } } } // update sobjects @@ -65,9 +75,14 @@ public class Async { } if(!sObjs.isEmpty()) { try { update sObjs; } catch (Exception e) { System.debug('Error updating SObjects'); } } } // delete sobjects @@ -83,9 +98,14 @@ public class Async { } if(!sObjs.isEmpty()) { try { delete sObjs; } catch (Exception e) { System.debug('Error deleting SObjects'); } } } /***********************/ @@ -94,11 +114,24 @@ public class Async { // list of sobjects public static String prepare(List<SObject> sObjs) { try { return JSON.serialize(sObjs); } catch (Exception e) { System.debug('Error in SObject List serialization'); } } // single sobject public static String prepare(SObject sObj) { try { return JSON.serialize(new List<SObject>{sObj}); } catch (Exception e) { System.debug('Error in SObject serialization'); } } } -
kevinohara80 revised this gist
Feb 10, 2012 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,12 +1,13 @@ /* * Author: Kevin O'Hara * Date: 02/10/2012 * * Description: The Async class aims to circumvent a limitation of asynchronous (@future) * methods in Salesforce. The current @future implementation will only allow for primitives * or collections of primitives to be passed into an @future method. The Async class uses * native JSON serialization/deserialization to allow for passing an SObject, or List<SObject> * into an asynchronous method for DML operations. A helper method is also included for making * the serialization processes simpler. */ public class Async { -
kevinohara80 revised this gist
Feb 10, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ * Author: Kevin O'Hara * Date: 02/10/2012 * Description: The Async class aims to circumvent a limitation of asynchronous (@future) * methods in Salesforce. The current @future implementation will only allow for primitives * or collections of primitives to be passed into an @future method. The Async class uses * native JSON serialization/deserialization to allow for passing an SObject, or List<SObject> * into an asynchronous function. A helper method is also included for making the serialization -
kevinohara80 revised this gist
Feb 10, 2012 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,6 @@ /* * Author: Kevin O'Hara * Date: 02/10/2012 * Description: The Async class aims to circumvent a limitation of asynchronous (@future) * functions in Salesforce. The current @future implementation will only allow for primitives * or collections of primitives to be passed into an @future method. The Async class uses -
kevinohara80 revised this gist
Feb 10, 2012 . 1 changed file with 10 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,13 @@ /* Author: Kevin O'Hara * Description: The Async class aims to circumvent a limitation of asynchronous (@future) * functions in Salesforce. The current @future implementation will only allow for primitives * or collections of primitives to be passed into an @future method. The Async class uses * native JSON serialization/deserialization to allow for passing an SObject, or List<SObject> * into an asynchronous function. A helper method is also included for making the serialization * processes simpler. */ public class Async { /***********************/ -
kevinohara80 revised this gist
Feb 10, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -8,7 +8,7 @@ for(Lead l : lds) { l.FirstName = 'BLAHHH'; } // 3. Use the prepare() helper method to serialize to JSON, then call the appropriate DML function Async.updateSObjects(Async.prepare(lds)); // RESULT: Your DML is offloaded to an async request -
kevinohara80 revised this gist
Feb 10, 2012 . 1 changed file with 7 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,14 @@ // EXAMPLE // 1. Query some leads List<Lead> lds = [SELECT Id, FirstName, LastName FROM Lead LIMIT 2]; // 2. Make some changes for(Lead l : lds) { l.FirstName = 'BLAHHH'; } // 3. Use the helper method to serialize to JSON, then call the appropriate DML function Async.updateSObjects(Async.prepare(lds)); // RESULT: Your DML is offloaded to an async request -
kevinohara80 revised this gist
Feb 10, 2012 . No changes.There are no files selected for viewing
-
kevinohara80 revised this gist
Feb 10, 2012 . No changes.There are no files selected for viewing
-
kevinohara80 revised this gist
Feb 10, 2012 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -19,6 +19,7 @@ public class Async { if(!sObjs.isEmpty()) { insert sObjs; } } // upsert sobjects @@ -36,6 +37,7 @@ public class Async { if(!sObjs.isEmpty()) { upsert sObjs; } } // update sobjects @@ -53,6 +55,7 @@ public class Async { if(!sObjs.isEmpty()) { update sObjs; } } // delete sobjects @@ -70,6 +73,7 @@ public class Async { if(!sObjs.isEmpty()) { delete sObjs; } } /***********************/ -
kevinohara80 created this gist
Feb 10, 2012 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,88 @@ public class Async { /***********************/ /* ASYNC CRUD METHODS */ /***********************/ // insert sobjects @future public static void insertSObjects(String jsonString) { List<SObject> sObjs = new List<SObject>(); try { sObjs = (List<SObject>) JSON.deserialize(jsonString, List<SObject>.class); } catch (Exception e) { System.debug('Error in JSON deserialization'); } if(!sObjs.isEmpty()) { insert sObjs; } } // upsert sobjects @future public static void upsertSObjects(String jsonString) { List<SObject> sObjs = new List<SObject>(); try { sObjs = (List<SObject>) JSON.deserialize(jsonString, List<SObject>.class); } catch (Exception e) { System.debug('Error in JSON deserialization'); } if(!sObjs.isEmpty()) { upsert sObjs; } } // update sobjects @future public static void updateSObjects(String jsonString) { List<SObject> sObjs = new List<SObject>(); try { sObjs = (List<SObject>) JSON.deserialize(jsonString, List<SObject>.class); } catch (Exception e) { System.debug('Error in JSON deserialization'); } if(!sObjs.isEmpty()) { update sObjs; } } // delete sobjects @future public static void deleteSObjects(String jsonString) { List<SObject> sObjs = new List<SObject>(); try { sObjs = (List<SObject>) JSON.deserialize(jsonString, List<SObject>.class); } catch (Exception e) { System.debug('Error in JSON deserialization'); } if(!sObjs.isEmpty()) { delete sObjs; } } /***********************/ /* HELPER METHODS */ /***********************/ // list of sobjects public static String prepare(List<SObject> sObjs) { return JSON.serialize(sObjs); } // single sobject public static String prepare(SObject sObj) { return JSON.serialize(new List<SObject>{sObj}); } } This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ // update a couple of leads async List<Lead> lds = [SELECT Id, FirstName, LastName FROM Lead LIMIT 2]; for(Lead l : lds) { l.FirstName = 'BLAHHH'; } Async.updateSObjects(Async.prepare(lds));