This Node.js app shows you how easy it is to use the Salesforce User Interface API to create, read, update, and delete Salesforce records.
Salesforce uses User Interface API to build the Salesforce1 and Lightning Experience apps. Not only do you get data and metadata in a single response, but the response matches metadata changes made to the org by Salesforce admins. You don’t have to worry about layouts, picklists, field-level security, or sharing—all you have to do is build an app that users love.
- To authenticate Record Viewer with a Salesforce org, in the org, configure a connected app.
- For the Callback URL, enter
https://localhost:8443/oauth-redirect
. If you deploy the app to Heroku, Heroku will provide a different callback URL. Create a new Connected App using the Heroku callback URL. - Make a note of the OAuth consumer key to enter on the home page of the Record Viewer app.
- For the Callback URL, enter
- To allow the app to make cross-domain requests to Salesforce, in the org, choose Setup > CORS.
- Click New.
- For Origin URL Pattern, enter
https://localhost:8443
. If you're deploying to heroku, enterhttps://*.herokuapp.com
orhttps://some-domain.herokuapp.com
.
- Clone the RecordViewer repository.
- Set up Docker.
- To build and start the servers, run this Docker Compose command.
docker-compose build && docker-compose up -d
- After Docker finishes building and starts the containers, the web application is available at
https://localhost:8443/
.
If you're running docker in a VM, be sure to forward the ports exposed in your containers. This script forwards open ports in the boot2docker-VM
.
for i in {49000..49900}; do
VBoxManage modifyvm "boot2docker-vm" --natpf1 "tcp-port$i,tcp,,$i,,$i";
VBoxManage modifyvm "boot2docker-vm" --natpf1 "udp-port$i,udp,,$i,,$i";
done
To view a record, click a record in the Recent Items list. This list contains recently used items. If you don't see any records, go to your Salesforce org and select a record or two, then return to the Record Viewer app.
When viewing a record, you can click to Edit, Delete, or Clone the record.
To create a record, navigate to the app's home page and select an object from the dropdown. User Interface API supports all custom objects and some standard objects. If you select an unsupported object, the app will let you know.
To see the response from User Interface API that the app uses to build the page, click Show JSON.
All of the instructions below assume that you are within the root of the project directory.
-
Install the Heroku CLI
-
Log into Heroku through the command line
heroku login
-
Log into the Heroku Container Registry
heroku container:login
-
The Heroku application must be created
heroku create
-
Deploy the application
heroku container:push web
After creating the Connected App in Salesforce, follow these steps to set the default Login URL and Consumer Key on the default page.
-
To set the Login URL, run this command.
heroku config:set LOGIN_URL={url}
Substitute
{url}
with the URL of the server that the org is on. -
To set the Consumer Key, run this command.
heroku config:set CONSUMER_KEY={key}
Substitute
{key}
with the value from the Consumer Key field in the Connected App details.