I am new to APIs'. I have a requirement as follows. 1) Account has a field called entity ID which is unique. 2) Other system will use my API to query for the Accounts which have entity ID. So how to provide them rest API for this query.

Any suggestions would be appreciated.

Thank you.

2 Answers 2


You need to build a custom REST API in salesforce and expose it to the other system and ask them to call your API for the Account Information:

Pls refer to this link below on how to create API using Apex and testing it out using postman application.


You need to share the URL with external applications to access you API:


They need to send a request to you as {"account_name":"Test"}

Based on this account name posted it will query and send the reponse as JSON.

HTTP Class:

    global class RestTestController {
    global static void getTestAccount() {

    RestRequest req = RestContext.request;
    RestResponse res = RestContext.response;
    res.addHeader('Content-Type', 'application/json');
    String jsonResponse = '';
    String accountName = req.params.get('account_name');

// No account_name parameter was found; return status 400
    if(accountName == null) {
        res.statusCode = 400;
        jsonResponse = '{"response": {"status": "Failure", "message": "MissingRequiredQueryParameter account_name"}}';
        res.responseBody = blob.valueOf(jsonResponse);

// Get the list of accounts that match the account_name sent in the request.
    List<Account> accounts = [SELECT Id, Name, Phone, Fax, Website
                              FROM Account
                              WHERE Name =: accountName];

// No accounts with matching account_name
    if( accounts.isEmpty()) {
        res.statusCode = 400;
        jsonResponse = '{"response": {"status": "Failure", "message": "No account matching account_name was found"}}';
        res.responseBody = blob.valueOf(jsonResponse);

// At least 1 account was found, JSON serialize it and send it back.
    try {
        res.statusCode = 200;
        jsonResponse = Json.serialize(accounts[0]);
        res.responseBody = blob.valueOf(jsonResponse);
    } catch ( Exception ex ) {
        res.statusCode = 500;
        jsonResponse = '{"response": {"status": "Failure", "message": "' + ex + '"}}';
        res.responseBody = blob.valueOf(jsonResponse);
  • my worry is, the way you have explained it is simple so anyone with the link to your APEX REST can post data to your org. How to prevent that from happening when the service that is posting the webhook to salesforce has no security measure Auth/OpenID in place ? THe service provider just tell you give me the link where I will post the notification. Nothing else.
    – aidonsnous
    Commented Jan 11 at 18:25

I think you should go for Force.com Apex Rest API. You can call your defined rest api class HTTPGET method having event id as parameter and return soql query result whatever apex search logic you want to implement in salesforce. Pass the event id parameter value as request body in json format that you will pass from external system and recieved response will be in json format of soql query that you can parse easily in external system.

For more information on this type of integration you should go through with below link to create a rest custom webservice is salesforce.

Creating REST APIs usingApex REST

  • OP, just to be clear, there is a Salesforce-issued REST API that allows you to perform basic operations (like those you listed) with minimal initial setup, and there is also the ability to create your own REST services in Apex. The link posted in this answer is mostly about the second more complicated option - check out this link for documentation on the basic REST API: developer.salesforce.com/docs/atlas.en-us.api_rest.meta/… Commented Aug 19, 2015 at 18:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .