|
| 1 | +# Event source for Salesforce |
| 2 | + |
| 3 | +This event source acts as a consumer of the [Salesforce stream API][salesforce-stream-api-docs] and forwards all messages it receives |
| 4 | +after wrapping them in a [CloudEvent][ce] envelope. |
| 5 | + |
| 6 | +## Prerequisites |
| 7 | + |
| 8 | +### Salesforce account |
| 9 | + |
| 10 | +Salesforce source uses [OAuth JWT credentials][salesforce-oauth-jwt] for service authentication. |
| 11 | + |
| 12 | +1. First you will need to generate a X509 certificate for signing and verifying requests. |
| 13 | +We will be using `openssl` but any other certificate generation tool should work. |
| 14 | + |
| 15 | +```sh |
| 16 | +openssl req -x509 -sha256 -nodes -days 36500 -newkey rsa:2048 -keyout tm-sf.key -out tm-sf.crt |
| 17 | +``` |
| 18 | + |
| 19 | +2. At Salesforce site select `Setup > Apps > App Manager`, click on `New Connected App`. |
| 20 | + |
| 21 | + - Fill in mandatory fields, then click `Enable OAuth Settings`. |
| 22 | + - Callback URL is mandatory but can be filled with any HTTPS data. |
| 23 | + - Enable `Use digital signatures` and upload the public cert (`tm-sf.crt` in the example above). |
| 24 | + - Add Scopes for `api` and `refresh_token, offline_access`. |
| 25 | + - Save. |
| 26 | + |
| 27 | +  |
| 28 | + |
| 29 | + - Select the Connected App from the list and at the click on `Manage`. |
| 30 | + - Click `Edit policies`. |
| 31 | + - Set Permitted users to `Admin approved users are pre-authorized`. |
| 32 | + - Save. |
| 33 | + |
| 34 | +  |
| 35 | + |
| 36 | + - Select the Connected App from the list and at the click on `Manage`. |
| 37 | + - Click `Manage Profiles`. |
| 38 | + - Add permissions on the data this user will have access to. |
| 39 | + - Save. |
| 40 | + |
| 41 | +3. Retrieve OAuth data to configure Triggermesh Source. |
| 42 | + |
| 43 | + - Select the Connected App from the list and at the click on `View`. |
| 44 | + - Copy `Consumer Key` |
| 45 | + - Reveal and copy `Consumer Secret` |
| 46 | + |
| 47 | +### Salesforce stream channel |
| 48 | + |
| 49 | +Refer to [Salesforce stream API][salesforce-stream-api-docs] on how to create stream channels: |
| 50 | + |
| 51 | + - Change Data Capture events: `/data/ChangeEvents` |
| 52 | + - PushTopics for streams based on single entity SOQL querys: `/topic/TicketsSold` |
| 53 | + - Standard Platform Events for Salesforce event monitoring: `/event/LoginEventStream` |
| 54 | + - Custom Platform Events for your SOQL plaform events: `/event/MyCustom__e` |
| 55 | + |
| 56 | +Each Streaming event type has a distinct [set of features][salesroce-event-features] |
| 57 | + |
| 58 | +### Certificate Key Secret |
| 59 | + |
| 60 | +The TriggerMesh Salesforce integration needs the certificate key to sign authentication requests with the Salesforce API. |
| 61 | +A [secret needs to be created at Triggermesh][tm-secret] that contains that certificate key. |
| 62 | +The file name containing the key will need to be renamed to `certKey`, then select `Secrets` > `+ ADD SECRET`, `File Upload` |
| 63 | + |
| 64 | + |
| 65 | + |
| 66 | +## Deploying an instance of the Source |
| 67 | + |
| 68 | +Open the Bridge creation screen and add a source of type `Salesforce`. |
| 69 | + |
| 70 | + |
| 71 | + |
| 72 | +In the Source creation form, give a name to the event source and add the following information: |
| 73 | + |
| 74 | +* **Broker** to send the events to. |
| 75 | +* **Client ID** as retrieved from Salesforce Connected App. |
| 76 | +* **Server** for authentication at Salesforce. |
| 77 | +* **User** for the Salesforce account. |
| 78 | +* **Channel** as configured at the Salesforce stream. |
| 79 | + |
| 80 | + |
| 81 | + |
| 82 | +After clicking the `Save` at the source you will be taken back to the Bridge editor. Proceed to adding the remaining |
| 83 | +components to the Bridge, then submit it. |
| 84 | + |
| 85 | +Wait a few seconds for all components to become ready, the green `Status` indicator for the bridge indicates that the event source is ready to forward messages from the Salesforce event Stream. |
| 86 | + |
| 87 | + |
| 88 | + |
| 89 | +## Event types |
| 90 | + |
| 91 | +The Salesforce event source emits events of the following types: |
| 92 | + |
| 93 | +* `com.salesforce.stream.message` |
| 94 | + |
| 95 | + |
| 96 | + |
| 97 | + |
| 98 | + |
| 99 | +[salesforce-stream-api-docs]: https://developer.salesforce.com/docs/atlas.en-us.api_streaming.meta/api_streaming/ |
| 100 | +[salesforce-oauth-jwt]: https://help.salesforce.com/articleView?id=remoteaccess_oauth_jwt_flow.htm |
| 101 | +[salesroce-event-features]: https://developer.salesforce.com/docs/atlas.en-us.api_streaming.meta/api_streaming/event_comparison.htm |
| 102 | +[ce]: https://cloudevents.io/ |
| 103 | + |
| 104 | +[tm-secret]: ../guides/secrets.md |
| 105 | + |
| 106 | + |
0 commit comments