Lightning Function Demos
Node.js + Platform Events
This demo uses a combination of Flow, Evergreen Functions, CDC, and Lightning Web Components.
Rough 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
- Create 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.
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
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
sfdx run:function:start
On another terminal run the following:
cd functions/routeplanner
sfdx run:function --url=http://localhost:8080 -p=@data/sample-payload.json