Skip to main content
code formatting
Source Link
crmprogdev
  • 41k
  • 9
  • 58
  • 116

I am new to Salesforce callouts and batch concepts but here is the requirement that I am working on:

Requirement is to get data from a third party API and create lead objects in our salesforce and for this I need to be able to make more than 100 future calls.

For now, I created a simple class and invoke this class from Anonymous Apex window in developer console.

This class makes callouts:

public with sharing class CallOutExample {

public void submitHttpRequest(){
    HttpRequest req = new HttpRequest();
    
    req.setMethod('GET');
    
    req.setEndPoint('http://www.example.com/endpoint');

    Http httpObj = new Http();
    HttpResponse res;
    String jsonString;
    
    List<Lead> leadObjList = new List<Lead>();

    for(Integer j =0; j <105; j++){
        
        res = httpObj.send(req);
        jsonString = res.getBody();
        
        Map<String,Object> jsonMapObj = (Map<String, Object>)JSON.deserializeUntyped(jsonString);
        
        List<Object> leadJsonObjList = (List<Object>)jsonMapObj.get('leadJson');
        
        for(Integer i=0; i<leadJsonObjList.size(); i++){
            // Here I take values for the last name, first name, phone number and everything from each lead Json object
            // and create lead objects and to the list
            Lead leadObj = new Lead(); //Assuming I am setting all the values
            leadObjList.add(leadObj);
        }   
        
    }

    Database.insert(leadObjList);
    
} 

}

}

And then I am invoking this method with the below code from anonymous apex:

CallOutExample obj = new CallOutExample();

obj.submitHttpRequest();

Can somebody point me in right direction on how to achieve this:

If iI write a batch class, will I be able to make more than 100 callouts? If so how do I implement the start method of the Batchable interface?

I am new to Salesforce callouts and batch concepts but here is the requirement that I am working on:

Requirement is to get data from a third party API and create lead objects in our salesforce and for this I need to be able to make more than 100 future calls.

For now, I created a simple class and invoke this class from Anonymous Apex window in developer console.

This class makes callouts:

public with sharing class CallOutExample {

public void submitHttpRequest(){
    HttpRequest req = new HttpRequest();
    
    req.setMethod('GET');
    
    req.setEndPoint('http://www.example.com/endpoint');

    Http httpObj = new Http();
    HttpResponse res;
    String jsonString;
    
    List<Lead> leadObjList = new List<Lead>();

    for(Integer j =0; j <105; j++){
        
        res = httpObj.send(req);
        jsonString = res.getBody();
        
        Map<String,Object> jsonMapObj = (Map<String, Object>)JSON.deserializeUntyped(jsonString);
        
        List<Object> leadJsonObjList = (List<Object>)jsonMapObj.get('leadJson');
        
        for(Integer i=0; i<leadJsonObjList.size(); i++){
            // Here I take values for the last name, first name, phone number and everything from each lead Json object
            // and create lead objects and to the list
            Lead leadObj = new Lead(); //Assuming I am setting all the values
            leadObjList.add(leadObj);
        }   
        
    }

    Database.insert(leadObjList);
    
}

}

And then I am invoking this method with the below code from anonymous apex:

CallOutExample obj = new CallOutExample();

obj.submitHttpRequest();

Can somebody point me in right direction on how to achieve this:

If i write a batch class, will I be able to make more than 100 callouts? If so how do I implement the start method of the Batchable interface?

I am new to Salesforce callouts and batch concepts but here is the requirement that I am working on:

Requirement is to get data from a third party API and create lead objects in our salesforce and for this I need to be able to make more than 100 future calls.

For now, I created a simple class and invoke this class from Anonymous Apex window in developer console.

This class makes callouts:

public with sharing class CallOutExample {

public void submitHttpRequest(){
    HttpRequest req = new HttpRequest();
    
    req.setMethod('GET');
    
    req.setEndPoint('http://www.example.com/endpoint');

    Http httpObj = new Http();
    HttpResponse res;
    String jsonString;
    
    List<Lead> leadObjList = new List<Lead>();

    for(Integer j =0; j <105; j++){
        
        res = httpObj.send(req);
        jsonString = res.getBody();
        
        Map<String,Object> jsonMapObj = (Map<String, Object>)JSON.deserializeUntyped(jsonString);
        
        List<Object> leadJsonObjList = (List<Object>)jsonMapObj.get('leadJson');
        
        for(Integer i=0; i<leadJsonObjList.size(); i++){
            // Here I take values for the last name, first name, phone number and everything from each lead Json object
            // and create lead objects and to the list
            Lead leadObj = new Lead(); //Assuming I am setting all the values
            leadObjList.add(leadObj);
        }   
        
    }

    Database.insert(leadObjList);
    
} 

}

And then I am invoking this method with the below code from anonymous apex:

CallOutExample obj = new CallOutExample();

obj.submitHttpRequest();

Can somebody point me in right direction on how to achieve this:

If I write a batch class, will I be able to make more than 100 callouts? If so how do I implement the start method of the Batchable interface?

Source Link
javanoob
  • 9k
  • 15
  • 77
  • 143

How to make more than 100 callouts per transaction?

I am new to Salesforce callouts and batch concepts but here is the requirement that I am working on:

Requirement is to get data from a third party API and create lead objects in our salesforce and for this I need to be able to make more than 100 future calls.

For now, I created a simple class and invoke this class from Anonymous Apex window in developer console.

This class makes callouts:

public with sharing class CallOutExample {

public void submitHttpRequest(){
    HttpRequest req = new HttpRequest();
    
    req.setMethod('GET');
    
    req.setEndPoint('http://www.example.com/endpoint');

    Http httpObj = new Http();
    HttpResponse res;
    String jsonString;
    
    List<Lead> leadObjList = new List<Lead>();

    for(Integer j =0; j <105; j++){
        
        res = httpObj.send(req);
        jsonString = res.getBody();
        
        Map<String,Object> jsonMapObj = (Map<String, Object>)JSON.deserializeUntyped(jsonString);
        
        List<Object> leadJsonObjList = (List<Object>)jsonMapObj.get('leadJson');
        
        for(Integer i=0; i<leadJsonObjList.size(); i++){
            // Here I take values for the last name, first name, phone number and everything from each lead Json object
            // and create lead objects and to the list
            Lead leadObj = new Lead(); //Assuming I am setting all the values
            leadObjList.add(leadObj);
        }   
        
    }

    Database.insert(leadObjList);
    
}

}

And then I am invoking this method with the below code from anonymous apex:

CallOutExample obj = new CallOutExample();

obj.submitHttpRequest();

Can somebody point me in right direction on how to achieve this:

If i write a batch class, will I be able to make more than 100 callouts? If so how do I implement the start method of the Batchable interface?