2

We have an external application where few records gets updated or created on daily basis. We already implemented inbound calls to salesforce but it is scheduled for once a month. We need to schedule a class on daily basis from Salesforce to our application and get all updated/newly created records and sync them properly.

I tried to run in a single call but it will be a huge XML which crosses heap limit. So, I am making GET requests by offset 25 and getting 25 records (which are updated or created only) at a time and trying to validate. This is causing DML limit exception. I tried to use @future method and sending XML string to it. in this case, I will be calling same future class multiple times and tried to make DML operations asynchronously. 0-25 records it's fine. But while making callout for 25-50 I am getting System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out. Same error for equable apex controller.

I was planning to use a batch apex after storing XML parse values in a variable but CPU time exceed exception is hitting. Records count that I am getting can be a overall of 500-5000. I request an expert advice to approach this situation. Thank you.

1 Answer 1

1

Try to implement next:

  1. Create Batch ith Database.AllowsCallouts interface implemented.
  2. Create Schedulable class to run your batch on a daily basis.
  3. Callouts and then DML do in execute method. Set callout timeout 120 seconds using setTimeout() method on HttpRequest instance. Callouts are not taken in the CPU time limit so don't worry.
  4. Play around with the executeBatch() method scope argument in order to avoid any limits to be exceeded.

This should help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.