+ Start a Discussion

sample code for REST CallIns example

Hi all
Scenario : while sending Member ID/ Caller ID, need to fetch details like contact channel, contact subscriber......details from Custom object (custom obj : for example ABD)
Could you please proivide sample code for above requiremnet and what API details i need to provide to third party application ?

Keyur  ModiKeyur Modi

Hi Sekhar,

You can refer below link for your requirement.


http://developer.force.com/gettingstarted?title=page/Getting_Started_with_the_Force.com_REST_API (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_rest_code_sample_basic.htm)

You need to share UserName , Passowd for the API user and you Need to creat "Connected App".From Connected App you have to share ClinetId, secreat Key, end point URL for your Rest class.

Link "How to create Connected App" :- https://help.salesforce.com/articleView?id=connected_app_create.htm&type=5

Please let me know if you need any further information from my side. 

Keyur Modi


Hi Keyur, thanks for your replay... I need fetch values from third party application to Salesforce. for example : in third party application fields like caller id, member ID.....these details how can i fetch into SFDC. what are the steps need to do for acheive this requirement ? what are APIs we need to provide to third party from SFDC ? any sample code for this requiremnt?
Keyur  ModiKeyur Modi

Hi Sekhar, 

I understand your requirement. You want to do call out and get the information from the third party. 
1. you need to have end point URL from third party. with help of this end point url  you can get the relevant information. 
2. you need to active that url access from salesforce. for that you have to configure Remote site settings (refer below link)
3. Create apex class which will help you to make call out with help of HTTP.

Sample class to make call out from apex class.

public class HttpCalloutSample {

  // Pass in the endpoint to be used using the string url
  public String getCalloutResponseContents(String url) {

    // Instantiate a new http object
    Http h = new Http();

     // Instantiate a new HTTP request, specify the method (GET) as well as the endpoint
    HttpRequest req = new HttpRequest();
    req.setEndpoint(url); // end point url of your third party 
    req.setMethod('GET'); // check the method type

    // Send the request, and return a response
    HttpResponse res = h.send(req);
    return res.getBody();

Please let me know if you need further guidance.

Keyur Modi