Activity › Forums › Salesforce® Discussions › Fetch Account Records Using Rest Api in Salesforce
-
Fetch Account Records Using Rest Api in Salesforce
Posted by Vikas Kumar on December 12, 2016 at 2:28 PMHi Everyone,
I had Fetched the security Token Using GET method But not able to get the syntax for fetching Account records
Thanks
Vikas Kumar replied 9 years, 3 months ago 2 Members · 2 Replies -
2 Replies
-
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&username=vikasm.mishra@algoworks.com&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
- [adinserter block='9']
-
Log In to reply.