You need to sign in to do that
Don't have an account?
Calling apex class from external website via POST method
I am trying to figure out a way to expose the functionalities of SalesForce via API so that I can use my business logic with my custom Android app/web-page which calls API via POST.
However, I have been unable to find a comprehensive solution. Any help will be greatly appreciated as I am aware of functionalities of SalesForce. But, I am not aware of exposing the Apex class as an endpoint.
This is what I would like to do as a basic starter:
Write an Apex class which takes two numbers as inputs and returns the sum of two numbers. I do know to do this via Lightning Component and I have read about VisualForce page. However, I have a requirement where I have to integrate SalesForce with vanilla HTML, Javascript and CSS if possible. So, POST would be convenient.
My attempts before asking this question:
I read lots of official documentation. I also got to know about Session ID and how that is being protected in developer console and how I can get it via workarounds. All nice. But, these official documentations did not help me design one Apex class which can do the use case mentioned above. I read lot of community posts which were more helpful. But, I have been unable to cobble them up together and test it via postman. Thanks for the time and consideration.
All you need do is expose your apex method using simple rest api and call this Rest API from the Android App by passing OAUTH Details Here there is a webservice running at url
https://yoursfinstance/services/apexrest/SumData
when you hit this endpoint after authorization, you can able to return the response to caller
http://amitsalesforce.blogspot.com/2017/06/test-salesforce-api-by-postman-rest.html
http://amitsalesforce.blogspot.com/2017/06/test-salesforce-api-by-postman-rest.html
https://docparser.com/blog/post-file-salesforce-apex-external-http-webservices/
https://apexcoder.com/2016/12/13/how-to-created-and-use-apex-rest-services-in-salesforce/
http://kalyanlanka.blogspot.com/2014/08/calling-apex-rest-service-using-postman.html
{
"access_token": "",
"instance_url": "",
"id": "",
"token_type": "",
"issued_at": "",
"signature": ""
}
From here, I tried to hit this url via POST https://yoursfinstance/services/apexrest/SumData
However, I am getting the following response.
[
{
"message": "Session expired or invalid",
"errorCode": "INVALID_SESSION_ID"
}
]
P.S.: I also tried https://jsforce.github.io/ But, I am not able to get this simple addition web-page up and running.