Future Method
But thankfully there is a way you can do using JSON serialize|deserialize methods.
public with sharing class InsertAccountFuture { public static void createAccountUsingFuturer () { List<String> lstAccount = new List<String>(); Account a1 = new Account('Sample Acount1'); Account a2 = new Account('Sample Acount2'); Account a3 = new Account('Sample Acount3'); lstAccount.add(JSON.serialize(a3)); lstAccount.add(JSON.serialize(a2)); lstAccount.add(JSON.serialize(a3)); createAccounts(lstAccount); } @future static void createAccount(List<String> lstAccount) { List<Account> insAccounts=new List<Account>(); for (String ser : lstAccount) { insAccounts.add((Account) JSON.deserialize(ser, Account.class)); } if(!insAccounts.isEmpty()){ insert insAccounts; } } }
No comments :
Post a Comment