Code Monkey home page Code Monkey logo

external-data-change-client's Introduction

External Data Change Client

Codey Warehouse is a sample client that showcases business process automation with data changes from an external system. The client is an application to a sample OData provider that models aspects of a warehouse such as a product inventory and ordering system.

The client showcases these external data change concepts available with Salesforce connect OData version 4.0:

  • Visualforce page that subscribes to external data changes by means of Salesforce Streaming API
  • Apex trigger that is called on external data changes

Warehouse Sample Application

The Codey Warehouse sample application illustrates implementation aspects of a warehouse:

  • A customer logs into the warehouse portal implemented by a Salesforce Visualforce page. On this page, the customer can browse special product deals of the last 24 hours and can place orders. New deals will show as they are made available in Codey's warehouse.

  • A customer gets notified via SMS or E-Mail about special deals for products with low inventory. The customer might not want to miss out on a great deal. The customer gets notified when the order has been shipped.

  • A customer can set up an automated order process with Apex triggers

  • An example with Process Builder showcases how to react to shipment events and declaratively interact with external objects.

  • The warehouse administrator can automate a flash sale with Batch Apex

Prerequistes

  • You need a Salesforce account with a license to create a Salesforce OData 4.0 connector: OData 4.0 Adapter for Salesforce Connect

  • Triggers on external objects is in Beta for the Salesforce Winter '19 release. You can sign up for the Beta Program by submitting a support case.

  • External objects in Process Builder is currently not available and will be available in the Salesforce Spring '19 release. Exclude the flows and flowDefinitions folders from force-app/main/default before deploying on an earlier release.

  • An OData 4.0 provider with remote data change tracking capability: OASIS OData Version 4.0 Protocol: Requesting Changes. The implementation on the provider should follow the entities in the OData metadata warehouse/Warehouse.OData.Metadata.xml

  • Optional: Twilio Account to demonstrate the sending of SMS messages

Setup

  1. Get the Salesforce development environment Salesforce DX CLI
  2. Clone this Git repository. warehouse holds the Warehouse sample application in Salesforce DX source format. This sample application has all components needed, including the external object and external data source to talk to the sample Warehouse OData provider. Some of the parameters are tied to an account, so best to edit them now before deploying:
    1. Edit the endpoint in the external data source to set it to your OData provider: warehouse/force-app/main/default/dataSources/Warehouse.dataSource-meta.xml.
    2. To send SMS, update the named credential Twilio to your Twilio account or other SMS provider endpoint to https://api.twilio.com/Accounts<Account Open Date>/<User/Account Name>/Messages.json and the username to the Twilio's account username in warehouse/force-app/main/default/namedCredentials/Twilio.namedCredential
    3. To send email from your process, change all references in ShipmentTrackingNotification-1.flow from :email to your email address.
  3. Deploy the application to your org. Below are instructions for the Salesforce DX CLI
    1. Log into your org - a browser with the Salesforce login opens: sfdx force:auth:web:login
    2. Go to your project: cd warehouse
    3. Set your default username for the org you work with: sfdx force:config:set defaultusername=<your username>
    4. Convert the DX project to Salesforce deployable metadata: sfdx force:source:convert
    5. Deploy the metadata directory to your org: sfdx force:mdapi:deploy -d metadataPackage_<number sequence>
  4. In your org's setup, type Permission Sets in the Quick Find box and open the Permission Set Codey Outdoor Fitters. Click on Manage Assigments and assign the application's permission set to your user.
  5. To send email or SMS messages to sample customers, do the following:
    1. Create a new Customer__c record. Choose whether to receive EMail or SMS messages
    2. The customer name needs to match an existing Salesforce User. The Salesforce's User Email is used to send Email messages.
    3. Optional: For SMS, navigate to Setup > Administer > Security Controls > Named Credentials and look for Twilio. Update the user credentials for your SMS account. By default, it is set to no authentication.
  6. Enable data change capture for the external objects Products and Product Orders on the external object setup page by checking Track Data Changes.

Dojo Dependencies

  • The Dojo base libraries are included by direct reference in Warehouse.page
<apex:includeScript value="//ajax.googleapis.com/ajax/libs/dojo/1.12.1/dojo/dojo.js"/>
  • The Cometd dojox library is version 3.1.3 available under warehouse/force-app/main/default/staticresources/CometdDojo313Zip. They can be updated from Github cometd/cometd-dojo

There is a small bug where the common Cometd parts are under cometd-dojo-3.1.3/org. The package file cometd.js needs to be moved to the directory cometd: So from org/cometd.js to org/cometd/cometd.js.

  • The Warehouse client Dojo classes are under staticresources

The static Dojo library zip files are referenced in the Visualforce page as follows before loading dojo.js:

    <script type="text/javascript">
        dojoConfig= {
            async: true,
            paths: {
                "dojox/cometd": "{!URLFOR($Resource.CometdDojo313Zip, '/cometd-dojo-3.1.3/cometd')}",
                "cometd": "{!URLFOR($Resource.CometdDojo313Zip, '/cometd-dojo-3.1.3/org/cometd')}",
                "warehouse": "{!URLFOR($Resource.ExternalDataChangeClientZip, '/warehouse')}",
                "data": "{!URLFOR($Resource.ExternalDataChangeClientZip, '/data')}",
                "channel": "{!URLFOR($Resource.ExternalDataChangeClientZip, '/channel')}"
            }
        };
    </script>

Trying It Out

Once the application has been deployed, log into your Salesforce org. You should see these artifacts:

  • Codey Outdoor Fitters - Your Deals The application with the tabs Customers, Product Deals
  • Codey Outdoor Fitters Warehouse The application that holds the tabs Customers, Product Orders, Products and Flash Sale This application illustrates the state of the warehouse in Codey's Salesforce org for example.
  • Daily Deals: The tab that shows the deals of the last 24 hours and new deals as they're available.
  • Products: The warehouse product inventory. This is the external object Products__x
  • Product Orders: Customer orders represented by the external object ProductOrders__x
  • Customers: The customers buying products from the warehouse. This is the custom object Customer__c. It holds customer details, for example whether they are interested in deals and whether they would like to be notified for deals and orders by SMS or E-Mail.
  • FlashSale: Visual force page to promote a set of products for a flash sale.
  • FlashSaleJob: Flash sale batch Apex job working on a larger set of external objects asynchronously
  • LowOnStock: Apex trigger on Products__x that sends an SMS when products are low on stock for deals that customers are interested in.
  • OrderShipped: Apex trigger on ProductOrders__x that sends an SMS when an order is shipped.
  • CustomerNotificationAction: An invocable action to send customer notifications from a process.
  • ShipmentTracking: Platform event sent for updated order shipping status.
  • ShipmentTrackingNotification: Process that reacts to published shipment tracking events.

To get external changes from the warehouse, enable external data change tracking for the external objects Products__x and ProductOrders__x. Edit the Product inventory to see notifications on your daily deals page.

To enable or disable external change tracking, check the flag Track Data Changes on the external object setup page. You can also see the current status under Change-Tracking Status.

To set the endpoint for your OData 4.0 provider, you can edit warehouse/force-app/main/default/dataSources/Warehouse.dataSource-meta.xml or update the URL for the external data source Warehouse on its setup page:

<?xml version="1.0" encoding="UTF-8"?>
<ExternalDataSource xmlns="http://soap.sforce.com/2006/04/metadata">
    <customConfiguration>{&quot;inlineCountEnabled&quot;:&quot;true&quot;,&quot;csrfTokenName&quot;:&quot;&quot;,&quot;requestCompression&quot;:&quot;false&quot;,&quot;pagination&quot;:&quot;CLIENT&quot;,&quot;Change-Tracking Interval&quot;:&quot;300&quot;,&quot;noIdMapping&quot;:&quot;false&quot;,&quot;format&quot;:&quot;JSON&quot;,&quot;compatibility&quot;:&quot;DEFAULT&quot;,&quot;csrfTokenEnabled&quot;:&quot;false&quot;,&quot;timeout&quot;:&quot;120&quot;,&quot;searchEnabled&quot;:&quot;true&quot;}</customConfiguration>
    <endpoint> --- Set your endpoint here ---</endpoint>
    <isWritable>true</isWritable>
    <label>Warehouse</label>
    <principalType>Anonymous</principalType>
    <protocol>NoAuthentication</protocol>
    <type>OData4</type>
</ExternalDataSource>

external-data-change-client's People

Contributors

tpollingsf avatar jamesward avatar svc-scm avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.