HttpCallOut from a batch
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
global class BatchName implements Database.Batchable<sObject>,<strong>Database.AllowsCallouts</strong> { public String uri; public String requestUri; public BatchName(String requestUri){ requestUri = requestUri; } global Database.QueryLocator start(Database.BatchableContext BC){ String query = 'Your query goes here'; return Database.getQueryLocator(query); } global void execute(Database.BatchableContext BC, List<YourObject> scope){ /* Call Your Http CallOut Service Class */ MyServiceClass srv = new MyServiceClass(this.requestUri); Map<String, Object> jsonMap= srv.YourMethod(); for (YourObject obj : scope){ obj.FieldName = String.valueOf(jsonMap.get('keyName')); } update scope; } global void finish(Database.BatchableContext BC){ } } |
Remember to mention Allowcallouts=true on batch context then you can do callout in batch job
0