Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sales Force Exposing Custom Objects via REST API

I am new to sales force and I have a problem. I would like to manipulate (created,update,delete and select) data from my custom objects using the REST API.

I have managed to get the sample working and it is sending me the data for accounts. Details

Now I would like to do the same for the Custom Object I have created.

I have tried this code but it is not working.

HttpClient httpclient = new HttpClient();
GetMethod get = new GetMethod(instanceUrl + "/services/data/v22.0/sobjects/Employee__c/EC-1000");
get.setRequestHeader("Authorization", "OAuth " + accessToken);
httpclient.executeMethod(get);
System.out.println("Status:" + get.getStatusCode());
System.out.println("Status Text:" + get.getStatusText());

Output is: Status:404 Status Text:Not Found

I created an object with name employee and ID EC-1000.

The above works for the default objects that is Account.

like image 283
ABJ Avatar asked Aug 03 '11 07:08

ABJ


People also ask

How do I expose a Salesforce data using REST API?

In this case you want to expose a REST API and then you have to code a class with @RestResource annotation. Check this example: @RestResource(urlMapping='/myserviceendpoint/*') global with sharing class MyRestService { @HttpGet global static void doGet() { String result = ''; RestRequest request = RestContext.

How do I access custom objects in Salesforce?

Much like a Standard Object, your new Custom Object can be accessed and edited via the Object Manager. From Setup, click the Object Manager tab. Scroll down the object list and click on your new custom object Vehicle Interest. Within the Details section, click Edit.

Can Salesforce Call external REST API?

We can call an external REST service and can update, delete or get some data which is required inside Salesforce. For Explanation we are going to call a currency conversion REST API from Apex and fetch the conversion rate in real time.

Does Salesforce support REST API?

REST API provides a powerful, convenient, and simple REST-based web services interface for interacting with Salesforce.


1 Answers

It works exactly the same way, except you use your custom object's API name instead of the standard object name, e.g. If you have a custom object called Handsets, its api name will be Handsets__c, and you can do a POST to /services/data/v22.0/sobjects/Handsets__c to create a new one.

To access a particular record you need the 18 character record Id, just like for the account (or you need an externalId field setup).

like image 172
superfell Avatar answered Oct 05 '22 19:10

superfell