I wanted to Bulkify my code to be able to update/create a long list of account for which I need to callout to my api.
I know that I can't do more than 50 callouts per future methods. But using Queueable Jobs I can't add up to 50 jobs to the queue.
So I'm sending the list of account inside a JSON with one CallOut :
Code In my trigger :
trigger AccountTrigger on Account (after insert, after update) {
List<Account> lstJson =new List<Account>();
for(Integer i=0;i<Trigger.new.size();i++){
Account account = Trigger.new[i];
lstJson.add((account));
}
/// Then i send my list of account to my Future Task
Map<string, List<Account>> accountMap = new Map<string, List<Account>>();
// Normally I should only Serialize the JSONLIst but our api has a problem...
accountMap.put('items', lstJson);
FutureTaskCreator.sendNotification(JSON.serialize(accountMap));
Then I call my API inside the callout :
public class FutureTaskCreator {
@future(callout=true)
public static void sendNotification(String json_string){
//my code
}
}
Is it a good way to implement it ? I've hit a limititation in both Queue and Callout...
Thanks for feedback to improve the method