This demo uses a combination of Flow, Salesforce Functions, CDC, and Lightning Web Components.
Demo flow:
- Open account record
- Click Quick Action "New Delivery"
- Enter data in Flow, which will create a Platform Event
- Wait for "Current Deliveries" to update (CDC listens in LWC)
This demo uses Salesforce Functions local development environment integrated with a scratch org, you can use a Developer Edition Org.
- Create a scratch org.
sfdx force:org:create -s -f config/project-scratch-def.json -a routeplannerdemo
- Push source to scratch org.
sfdx force:source:push
- Assign permissionset
sfdx force:user:permset:assign -n RoutePlanner
- Import sample data
sfdx force:data:tree:import -p data/Account-Service__c-plan.json
- Open the org
sfdx force:org:open
- In Setup go to Data -> Data Integration Rules, and activate Geocodes for Account Shipping Address.
As the DX is in flux this section only describes the minimum needed information.
- The function for this demo is located in
functions/routeplanner
. - The permissionset to use is
RoutePlanner
- for function assignment and for the Platform Event assignment.
Once you complete the steps below to setup and run the Function you should see these records. DELIVERYROUTE__R.NAME shows the route the vehicle should take and NUMBER__C represents the waypoints on that route to each service location in the most optimal order.
DELIVERYPLAN__C DELIVERYROUTE__R.NAME VEHICLENAME__C NUMBER__C SERVICE__R.NAME
─────────────────────────────────────── ───────────────────── ────────────── ───────── ────────────────────────────
Delivery Plan @ 2019-02-09 15:43:09.845 R-00000000 Van 1 Delivery to Beniof Mansion
Delivery Plan @ 2019-02-09 15:43:09.845 R-00000000 Van 3 Delivery to Landmark
Delivery Plan @ 2019-02-09 15:43:09.845 R-00000001 Van 2 Delivery to Salesforce Tower
Delivery Plan @ 2019-02-09 15:43:09.845 R-00000001 Van 4 Delivery to Salesforce West
On a terminal run the following:
cd functions/routeplanner
sf run function start
On another terminal run the following:
cd functions/routeplanner
sf run function -l http://localhost:8080 -p=@data/sample-payload.json