How to insert, update... records by using the HTTP classes?

I need to insert and delete records over an apex controller by using HTTP classes. I need to do it over HTTP because the DML has to be done by the administrator and during the call the user is a regular user. By using HTTP I can specify the user and the password of the administrator, this will allow me to perform a DML as administrator.

  • Deserialize it into an object – EricSSH Aug 16 '17 at 16:46

There's a number of steps you need need to take into consideration to insert/update records using HTTP Classes.

as mentioned before, you can deserialize json object and use it or you can Parse it if JSON response include fields that you don't want to include in the record.

Since you're asking for http, the I'd expect that records are coming from 3rd party.

  1. Make sure you whitelist the ip
  2. Create the and sent http request
  3. Get the response and create a JSONParser object from it
  4. Iterate over the JSON object and retrieve your data
  5. Create your record
  6. Insert/Update your records

Simple example :

public void makeCallout {

Http http = new Http();
HttpRequest request = new HttpRequest();
Transient string cookie = 'X';
request.setHeader('Authorization', authheader);
request.setHeader('Cookie', cookie);
if (response.getStatusCode() == 200) {
    while (parser.nextToken() != null){
        if (parser.getCurrentToken() == JSONToken.START_ARRAY) {
            if (parser.getCurrentToken() == JSONToken.START_OBJECT){
                try {
                    if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() =='name')){
                        name = parser.getText();
    insert a;
| improve this answer | |
  • 1
    The overhead on JSON class is pretty high, just deserlize it in an object – EricSSH Aug 16 '17 at 17:15

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