+ Start a Discussion

Exposing a custom object via Apex Webservice

Hello All,


I am new to Salesforce.

We have this requirement.


a) We have a custom object that has 10 fields + 1-2 file attachments.

b) Expose this custom object via a webservice.The sole purpose of this webservice is to retrieve records from this custom object.

c) Our partner then ,using this webservice, will consume the records and load it in his system.


Is this possible to do it in Salesforce ?

Best Answer chosen by Admin (Salesforce Developers) 
Satyendra RawatSatyendra Rawat


sample of the web services code.



global with sharing class RESTCustomRecords {

global static CustomObj__c[] doGet(RestRequest request, RestResponse res)
String strName = request.params.get('Name');
String strId = request.params.get('Id');
if( strId != null )
//write query here
// return arrRecords;
return null;

global static String[] doPost( RestRequest request, RestResponse response )
Database.Saveresult saveResult = null;
String[] strResult = new String[2];
String strRecordId = request.params.get('Id');
String strParentId = request.params.get('ParentId');
String strName = request.params.get('Name');

if( strRecordId == null || strRecordId == '' )
//make data object of custom object and insert the record
strResult[0] = (saveResult.success) ? 'true' : 'false';
strResult[1] = saveResult.id;
return strResult;
return strResult;