Exposing the Salesforce Data as an Rest API

0 votes

how can I expose the Sales force data as an Rest API so the external System can consume it. I was think if I can create a Apex Class like below-

@RestResource(urlMapping='/GetAccounts/*')
global with sharing class GetAccounts {
    @HttpGet
    global static Account doGet() {
        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        String accountId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
        Account result = [SELECT Id, Name FROM Account WHERE Id = :accountId];
        return result;
    }
}


And for the external user to consume the data, I figured I could create a Connected App and give them the Username, Password, Consumer Key, and Consumer Secret, and they should be authenticating in Salesforce to acquire the URI and session ID. The API that is published above should be able to be called using the SessionID and URI. Is this the correct approach? Please let me know if there's anything I'm missing.


Is it feasible to utilise Swagger within the Apex Class, as there is a requirement to use Swagger with the API? Could you please explain how I may use Swagger with my API?

Apr 8, 2022 in SalesForce by surbhi
• 3,810 points
777 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In SalesForce

0 votes
0 answers

How to take test.salesforce.com while deployment as salesforce login url for api connection logic app?

In logic app i'm using salesforce connector after deployment ...READ MORE

Mar 1, 2022 in SalesForce by surbhi
• 3,810 points
807 views
0 votes
1 answer

How to take test.salesforce.com while deployment as salesforce login url for api connection logic app?

you are not passing the parameterValues, use ...READ MORE

answered Mar 2, 2022 in SalesForce by surbhi
• 3,810 points
749 views
0 votes
1 answer

How to take test.salesforce.com while deployment as salesforce login url for api connection logic app?

You are not passing the parameterValues, use ...READ MORE

answered Mar 9, 2022 in SalesForce by CoolCoder
• 4,400 points
563 views
0 votes
1 answer

How do i get all values from a global pick list in salesforce using REST Api?

Since API 39.0 it is possible to ...READ MORE

answered Mar 17, 2022 in SalesForce by CoolCoder
• 4,400 points
6,182 views
0 votes
0 answers

Salesforce API: How to identify a Case from an email reference code ("[Ref: ... :Ref]")?

1 I'm writing a Windows service that will ...READ MORE

Apr 5, 2022 in SalesForce by surbhi
• 3,810 points
574 views
0 votes
0 answers

Can Salesforce Shield Encryption encrypt data IN TRANSIT (or only at rest)?

Is Salesforce Shield Encryption solution encrypting data ...READ MORE

Apr 11, 2022 in SalesForce by surbhi
• 3,810 points
536 views
+2 votes
2 answers

Salesforce Interview questions

Here are some questions very important for ...READ MORE

answered Jan 11, 2019 in Career Counselling by Suresh
• 720 points
2,729 views
0 votes
1 answer

How to connect to salesforce from tableau?

Hi, follow these steps to connect to Salesforce: 1. ...READ MORE

answered Mar 25, 2019 in Tableau by Cherukuri
• 33,030 points
728 views
0 votes
1 answer

Power BI - Salesforce

Hi, Follow below steps: 1. Go to Data source. 2. ...READ MORE

answered Mar 25, 2019 in Power BI by Cherukuri
• 33,030 points
476 views
0 votes
2 answers

What is the best training for Salesforce ADM-201 Exam?

Hi @Vardhan, I took Edureka's Salesforce Training that covers all ...READ MORE

answered Jun 3, 2021 in Others by Jaya
• 140 points

edited Dec 22, 2021 by Soumya 535 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP