Salesforce Platform Developer II Exam

© examsiri.com
Question : 2 of 33
 
Marks: +1, -0
A company has code to update a Request and Request Lines and make a callout to their external ERP system's REST endpoint with the updated records.
public void updateAndMakeCallout (Map regs, Map regLines) {
  Savepoint sp = Database.setSavepoint ();
  try {
    insert regs.values();
    insert regsLines.values();
    HttpResponse response = CalloutUtil.makeRestCallout (regs.keySet(), regLines.keySet());
  } catch (Exception e) {
    Database.rollback (sp);
    System.debug (e);
  }
}
The CalloutUtil.makeRestCallout fails with a 'You have uncommitted work pending. Please commit or rollback before calling out' error.
What should be done to address the problem?
Go to Question: