Fetching JSON data from a Website through Salesforce SITES
How do we access another website UI from Salesforce Sites
a. We need to get our hands dirty with some code.b. Knowledge on Integration (REST API)
c. Remote site settings (configuration in SF)
d. Parsing JSON
d. Creating a site in SF
e. Access settings for the created site
BELOW IS THE OUTPUT
Salesforce site displaying data present on a website using REST API |
The Salesforce Force.com REST API lets you integrate Salesforce applications using standard HTTP methods. This can then be used to integrate Salesforce with other systems. With help of Apex REST, we can expose the data from Salesforce orgs and we can also fetch data from other systems which hits the particular endpoint (URL).
a. CODE
Class : Class to act as a Wrapper
As you can observe that the above class has the same naming conventions as the JSON data which we would be receiving from the website.
Class : Callout Controller
Visualforce page:
Site configuration
Now, create a site in Salesforce, if you are new and if you need not know how to create a site in Salesforce then refer this link. Once your site is created in its “Public Access Settings” then add the above created Class into “Enabled Apex Classes” and add the StockCheck VF page in 'Enabled Visualforce Pages'.
The above VFpage(Stockcheck) must be added to the site
Add Remote Site Settings :
Add Remote site setting from setup-->Security Controls-->RemoteSiteSettings |
Tadaaaaahh... The output of our site page (StockCheck) would look like this :
Displaying all the data fetched from the website and parsing the JSON and displaying them as needed.
Fetching JSON data from a Website through Salesforce SITES
Reviewed by dasfrogpractice
on
23:27
Rating:
Thank you much for sharing this wonderful post.
ReplyDeleteAWS Training in Chennai | AWS Training Institute in Chennai | AWS Training Center in Chennai