Advertisement
Stingerwasp

Create Records form json in apex

Mar 15th, 2023 (edited)
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.52 KB | Source Code | 0 0
  1. // Get the static resource name and path for the JSON file
  2. String resourceName = 'insert_static_resource_name_here';
  3. String resourcePath = '/resource/' + resourceName;
  4.  
  5. // Read the JSON file from the static resource
  6. String jsonString = System.resource.getResourceAsString(resourcePath);
  7.  
  8. // Deserialize the JSON string into a list of custom objects
  9. List<Account__c> newAccounts = (List<Account__c>) JSON.deserialize(jsonString, List<Account__c>.class);
  10.  
  11. // Insert the new records into Salesforce
  12. insert newAccounts;
  13.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement