What should the developer do? A developer writes the following - ProProfs Discuss
Topics
Products
Follow Us:

What should the developer do? A developer writes the following code:public with sharing class OrderControllerpublic PaqeReference sendOrder()Order__c order = new Order__cinsert order;ExternalOrder externalOrder = new ExternalOrder(order);Http h = new Http();HttpRequest req = new HttpRequest();req.setEndpoint('https://www.example.org/v1/orders');req.setMethod('POST');req.setBody(JSON.serialize(externalOrder));HttpResponse res = h.send(req);order = (ExternalOrder)JSON.deserialize(res.getBody(), ExternalOrder.class);While testing the code, the developer receives the followmg error message:System.CalloutException : You have uncommitted work pending.



A. Use the asyncSend() method of the HTTP class to send the request in async context.
B. Ensure all callouts are completed prior to executing DML statements.
C. Move the web service callout into an @future method.
D. Use Database.insert (order, true) to immediately commit any database changes.

This question is part of PD2
Asked by Pal, Last updated: Jun 02, 2020

+ Answer
Request

1 Answer

Pal

Pal

Answered Apr 07, 2018

Move the web service callout into an @future method.
Use Database.insert (order, true) to immediately commit any database changes.
 

Search for Google images
Select a recommended image
Upload from your computer
Search for Google images
Select a recommended image
Upload from your computer
Search for Google images
Select a recommended image
Upload from your computer

Email Sent
We have sent an email to your address "" with instructions to reset your password.