Skip to content

heroku-examples/routeplanner-sfx

Repository files navigation

Route Planner Demo

Node.js + Platform Events

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)

Salesforce org setup

This demo uses Salesforce Functions local development environment integrated with a scratch org, you can use a Developer Edition Org.

  1. Create a scratch org.
sfdx force:org:create -s -f config/project-scratch-def.json -a routeplannerdemo
  1. Push source to scratch org.
sfdx force:source:push
  1. Assign permissionset
sfdx force:user:permset:assign -n RoutePlanner
  1. Import sample data
sfdx force:data:tree:import -p data/Account-Service__c-plan.json
  1. Open the org
sfdx force:org:open
  1. In Setup go to Data -> Data Integration Rules, and activate Geocodes for Account Shipping Address.

Functions setup

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.

Route Planner Function

diagram

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

Local Development

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

About

Traveling Salesperson Problem with Salesforce Functions

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published