-
Create Scratch Org
- Ensure you have ETCopyData SFDX plugin to load the data for the new scratch org.
sfdx plugins | grep "etcopydata"
- Clone this Github repo: https://github.com/eltoroit/realTimeSalesforce and navigate to that folder
git clone https://github.com/eltoroit/realTimeSalesforce.git
cd realTimeSalesforce
- Open the project in VS Code, located at
<REPO>/ScratchOrg
code ScratchOrg
- Open the terminal window
- Install the required npm libraries
npm install
- Create scratch org
npm run createOrg
- Ensure you have ETCopyData SFDX plugin to load the data for the new scratch org.
-
Setup ORG
- On the browser, open up the new Scratch Org
- During the creation of the scratch org, the setup window was opened showing the deployment status. you can reuse that window.
- If the window was closed, you can use
sf org open
- Verify your email address is associated with the scratch org owner
user user
- Click on astro avatar
- Click on
User User
- Update the email if needed
- Grab the credentials for the connected app
- Navigate to
Setup> Apps > App Manager
(/lightning/setup/NavigationMenus/home) - Find and view the connected app named
RealTimeSalesforce
- Click
Manage Consumer Details
and follow instructions - Copy the values in a new tab in VS Code
- Navigate to
- Enable Username/Password oAuth flow
- Navigate to
Setup > OAuth and OpenID Connect Settings
(/lightning/setup/OauthOidcSettings/home) - Toggle
Allow OAuth Username-Password Flows
to enable this, clickOK
- Navigate to
- On the browser, open up the new Scratch Org
-
Update variables in Postman
-
In VS Code, open the file
etLogs/_user.json
located inside the scratch org -
On a browser, login to your Postman account
-
Create a new workspace
- From the
Workspaces
menu, click onCreate Workspace
- Select blank workspace and click
Next
- Give it a name ad select the access (Personal, Team, Parner, or Public)
- Click
Create
- From the
-
Import the JSON file with the collection definition collection
- Click the
Import
button - Enter this URL: https://raw.githubusercontent.com/eltoroit/realTimeSalesforce/master/Other%20Files/ELTORO.IT%20Demos%20-%20Real-Time%20Salesforce.postman_collection.json
- Click the
-
Open the
variables
tab for that collection -
For these variables, ensure the
Current values
column has these values:Variable Current Value url https://test.salesforce.com username Copy this from the _user.json
filepassword Copy this from the _user.json
fileclientId This is the Consumer Key
obtained in the previous stepclientSecret This is the Consumer Secret
obtained in the previous stepSecretToken Leave this blank because the IP Ranges (0.0.0.0 ~ 255.255.255.255) have been set in the Admin profile -
Click
Persist all
to copy the values fromCurrent Value
toInitial Value
- ❌ WARNING: DO NOT click the reset button or you need to go back to the previous step since this does the opposite operation from what we want.
-
Click
Save
-
-
Validate settings are correct
- Postman must be using the
Desktop Agent
for the requests, specially for the Streaming API demo.- Make sure you install the required software from here: https://www.postman.com/downloads/postman-agent/
- Ensure the agent selected on the bottom right corner next to Cookies is set to
Desktop Agent
- You may need to select
Auto-Select Agent
- Toggle the
Auto-Select
off - Select
Desktop Agent
- Open the
/UNPW OAuth Tester
request in root of this this collection - Click
Send
- Validate
- You should receive a valid
access_token
- The
instance_url
should be valid for your scratch org
- You should receive a valid
- Postman must be using the
-
Now that we know the oAuth is properly configured, let Postman get its own access token
- Open the collection
- Click the
Authorization
tab for the collection - At the bottom of the page, click the
Get New Access Token
button - Follow the oAuth prompts
- Click
Proceed
- Click
Use Token
-
Let's use the access token inside Postman
- Find the
REST Query Account (OAuth)
request in root of this this collection - Click
Send
- You should receive a response with 2 records
- Find the
-
Postman must be using the
Desktop Agent
for the requests in this demo (see directions above) -
The
Streaming API
folder has 2 subfolders:Publisher
allows you to publish new events on the busSubscriber (Run This!)
is the actual implementation of Streaming API subscriber that uses long-polling
-
Subcribe to a Streaming API event
- Navigate to the
Subscriber (Run This!)
folder - Open the
Postman console
to see the different requests/responses in action - Select the
Pre-request Script
tab in this folder to configure the demo by indicating which event you want, and the replay Id.- Change the value in
line 16
to indicate whichchannel
to subscribe to - Change the value in
line 6
to indicate the value of thereplay Id
- Change the value in
- Click
Run
, a new tab should open - Click
Run ELTORO.IT Salesforce Postman Demos
to start the subscription - Look in the
Postman console
at the requests/responses in action
- Navigate to the
-
Publisher to a streaming event
- Use the proper request in the
Publisher
folder to publish the event needed to trigger the subscriber - Note: Generic events need to execute 2 requests in order. The first one gets the channel ID, the second one pblishes on that channel.
- For a better experience, use two browser tabs
- Use the proper request in the
- Open a new VS Code window for the
<REPO>/gRPC/SimpleDemo
folder - Install packages:
npm install
- Split the terminal in two panels side-by-side
- Run the gRPC server
npm run server
on one panel - Run the gRPC client
npm run client
on the other panel
-
Open a new VS Code window for the
<REPO>/gRPC/PubSub
folder -
Install packages:
npm install
-
Create a new
.env
file with these entriesKey Value SALESFORCE_AUTH_TYPE username-password SALESFORCE_LOGIN_URL https://test.salesforce.com SALESFORCE_USERNAME Copy this from the _user.json
fileSALESFORCE_PASSWORD Copy this from the _user.json
fileSALESFORCE_TOKEN leave blank PUB_SUB_ENDPOINT api.pubsub.salesforce.com:7443 -
Run the PubSub API client
npm run client
-
Go back to Postman and publish an event
- Use the proper request in the
Publisher
folder to publish the event needed to trigger the subscriber - Note: Generic events need to execute 2 requests in order. The first one gets the channel ID, the second one pblishes on that channel.
- Use the proper request in the
- Open a new VS Code window for the
<REPO>/WebSockets/Basic
folder - Install packages:
npm install
- Run the WebSocket server
npm run serve
- Open a new browser tab and navigate to http://localhost:3000/
- This opens a simple chat application
- Duplicate the tab and put both tabs side to side.
- Start chatting 😀
- Test the WebSockets server on Heroku
- The code for this server is here:
<REPO>/WebSockets/LWC
- The code for this server is here:
- Open a browser tab and navigate to https://et-realtimesf-basicws-6b1e66624e2a.herokuapp.com/
- This tab can be opened in multiple computers
- Click on the
Click Me
button, notice theping
andpong
times are different but very close. - Leave that WebSockets server tab open (you will see why in a minute)
- On a new tab, open the Scratch Org
- Go to
App Launcher
>LWC Demo
>Web Sockets
- Duplicate the tab
- Start interacting with the component
- Type something on the textbox
- Change the colors
- Notice how the other component(s) get automatically updated
- You could also see the messages and send them from the web page we left open