I have a scheduled process which runs every hour and call a method of another class which has a call to external wsdl. This method is annotated with @Future(callout = true) When I get data back from wsdl I process it and insert it into salesforce object. As the data is very huge I am encountering issue: Too Many DML statements: 151
Now I want each of the response record to be processed in different transaction so that I don't hit the salesforce limit. I tried annotating it with @future so that a separate transaction is created everytime. But now I get different issue that Future cannot be called from Future.
Code: Scheduled Class:
class HourlySchedule implements Schedulable {
global void execute(SchedulableContext SC) {
Client.call();
}
}
Class which does a callout to external wsdl and get the response:
class Client {
@future(callout = true) // this has to be there as Schedule class
// cannot do a callout to external service
public static void call() {
// callout to wsdl
// get response and process each client and its data
// here we can get 100's of client and each client can have
ProcessClass.process();
}
}
Class which process the data
class ProcessClass {
public static void process(String data) {
// multiple insert statments
// cannot reduce them further as I have to insert the parent object first and then insert child object for creating master-detail relationship.
}
}