I'm making integration to an external system and send them a request, and I get a JSON as a response via REST API.

The response has a lot of data to upsert to SF.

While upserting the Data inside the response - I want to validate the data.

After doing so, I want to send all the data that didn't pass the validation.

My question is - Do I need to have another request? Or can I use the response to send another data? (Like make the connection open)

Http h = new Http();
HttpRequest httpReq = new HttpRequest();
httpReq.setEndpoint('Some URL');
HttpResponse res = h.send(httpReq); //! GET the JSON HERE

 RootObject data = (RootObject) JSON.deserialize(res.getBody(), RootObject.class);

 Map<String,String> errorsMap = ValidateData(data);

 //Send the errorsMap (Keyset and Values to the external System again).
 //Do I need to create another request to it? - Means use the Http send method twice?

1 Answer 1


@Salvation yes you need to perform another HTTP callout as you did previously. The thing you want to be mindful is the order of operations for HTTP callouts and DML transactions:


You can’t make a callout when there are pending operations in the same transaction. Things that result in pending operations are DML statements, asynchronous Apex (such as future methods and batch Apex jobs), scheduled Apex, or sending email. You can make callouts before performing these types of operations.

  • Actually I thought to make the request at the Finish method of the batch - With values of a Map that includes all the Errors - and the finish is working in a separate transaction so it will be Ok I guess. Thank you very much for your help.
    – Salvation
    Commented Oct 23, 2019 at 13:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .