Activity Forums Salesforce® Discussions Fetch Account Records Using Rest Api in Salesforce

  • sushant

    Member
    January 16, 2017 at 2:29 pm

    Hi Vikas,

    The following example may help you:

    global class TestRESTAPI{

    global void authenticateAPI(){

    httprequest req = new httprequest();
    http testHttp = new http();

    req.setMethod('GET');
    req.setEndPoint('https://login.salesforce.com/services/oauth2/token');
    req.setBody('grant_type=password&client_id=3MVG9ZL0ppGP5UrBUp_MAQLjBuF1yI1xECRabWZ8No_gyZ4WF3HVrSDyMTTxN13GWhhhrH2Sqg84AsVR3Y0ib&client_secret=9013832611733751894&[email protected]&password=Test@1234');
    HttpResponse res = testHttp.send(req);
    System.debug(res.getBody());
    }

    global void getAccounts(){

    httprequest req = new httprequest();
    http testHttp = new http();

    req.setMethod('GET');
    req.setEndPoint('https://ap2.salesforce.com/services/data/v38.0/sobjects/Contact');
    req.setHeader('Authorization','OAuth 00D28000001yTWP!AQwAQMPFnsn66o3QnIG.vRfAwkPm1bBVumQlEB4rK.ywUQFzlfx6bvhLIH5XH18ilDT7CxD9o5Bu_kql4fN4r0J06Wj7N7rv');
    HttpResponse res = testHttp.send(req);
    System.debug(res.getBody());
    }
    global void postvalue(){
    httprequest req=new httprequest();
    http testHttp=new http();
    req.setMethod('POST');
    req.setEndPoint('https://ap2.salesforce.com/services/data/v38.0/sobjects/Account');
    req.setHeader('Authorization','OAuth 00D28000001yTWP!AQwAQD0UJZIVUyvnBXkNck7RN9TOqY0swbTwAlL2xjefUKrHqBqwN43yxnT26ghfUzGu82Zmy.oBKW2tn.UoheV9A7A9dZeu');
    req.setHeader('Content-Type', 'application/json');
    req.setBody('{"name" : "FromSushant"}');
    HttpResponse res=testHttp.send(req);
    System.debug(res.getBody());
    }
    }

    Thanks

  • Vikas Kumar

    Member
    January 18, 2017 at 1:49 pm

    Hi sushant,

    thanks its working !

    • This reply was modified 7 years, 3 months ago by  Vikas Kumar.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos