Simple Express app to query Salesforce with AppLink SDK using a different user as the one that invoked the API
Assumes you have two Salesforce users to log in with.
- One that is for an org that is enabled for Heroku Applink that you can try sample code in
- One that either has different access to the same org OR has access to a completely different org
The ultimate goal is that a query of Accounts using the second user login yields different results than if you were to query with the first user login, so you can tell from the results of the query that the second user login was indeed used.
The key features to make this work with AppLink Service Mesh are:
- add the service mesh buildpack
- add Heroku config var APP_PORT
- adjust the Procfile to launch service mesh
- in code, bind Express to $APP_PORT
DISCLAIMER -- This is a demo, not production code. Feel free to consult the code and use it to fuel your own ideas, but please do not assume it's ready to plug into a production environment as-is.
heroku create
heroku buildpacks:add heroku/heroku-applink-service-mesh
heroku buildpacks:add heroku/nodejs
heroku addons:create heroku-applink
heroku config:set APP_PORT=3000
heroku config:set OTHER_CONNECTION_NAME=MyOtherUser
heroku config:set HEROKU_APP_ID="$(heroku apps:info --json | jq -r '.app.id')"
git push heroku main
(Set permset for Manage Applink)
heroku salesforce:connect MyUser
heroku salesforce:authorizations:add MyOtherUser
heroku salesforce:publish api-spec.yaml --client-name=HerokuAPI --authorization-connected-app-name=ApplinkAccountsAccessConnectedApp --connection-name=MyUser
(Set HerokuAPI permset)
Run this anonymous Apex:
herokuapplink.HerokuAPI herokuAPI = new herokuapplink.HerokuAPI();
herokuapplink.HerokuAPI.GetAccounts_Response response = herokuAPI.GetAccounts();
System.debug(JSON.serializePretty(response));
Delete the Heroku app in the web dashboard or use this command:
heroku destroy
Delete the External Service "HerokuAPI" from your Salesforce Org as explained in these instructions.