0

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

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.

https://forceadventure.wordpress.com/2013/01/31/creating-a-custom-rest-api-in-salesforce/

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

https://Instance.salesforce.com/services/apexrest/test/test_rest_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:

    @RestResource(urlMapping='/test/test_rest_api/*')
    global class RestTestController {
    @HttpPost
    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);
        return;
    }

// 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);
        return;
    }

// 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);
        return;
    } catch ( Exception ex ) {
        res.statusCode = 500;
        jsonResponse = '{"response": {"status": "Failure", "message": "' + ex + '"}}';
        res.responseBody = blob.valueOf(jsonResponse);
        return;
    }
}
}
| improve this answer | |
0

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

| improve this answer | |
  • 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/… – Brian Mansfield Aug 19 '15 at 18:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.