5.2. Salesforce Connector

This connectors makes it possible to push and pull data to/from the Salesforce CRM. It can copy information betweenApache Unomi profiles and Salesforce Leads.

5.2.1. Getting started

  • Create a new developer account here:
  1. https://developer.salesforce.com/signup
  • Create a new Connected App, by going into Setup -> App Manager and click "Create Connected App"

  • In the settings, make sure you do the following:

  1. Enable OAuth settings -> Activated
  2. Enable for device flow -> Activated (no need for a callback URL)
  3. Add all the selected OAuth scopes you want (or put all of them)
  4. Make sure Require Secret for Web Server flow is activated
  • Make sure you retrieve the following information once you have created the app in the API (Enable OAuth Settings):
  1. Consumer key
  2. Consumer secret (click to see it)
  • You must also retrieve your user’s security token, or create it if you don’t have one already. To do this simplyclick on your user at the top right, select "Settings", the click on "Reset my security token". You will receive an emailwith the security token.

  • You are now ready to configure the Apache Unomi Salesforce Connector. In the etc/org.apache.unomi.sfdc.cfg filechange the following settings:

  1. sfdc.user.username=YOUR_USER_NAME
  2. sfdc.user.password=YOUR_PASSWORD
  3. sfdc.user.securityToken=YOUR_USER_SECURITY_TOKEN
  4. sfdc.consumer.key=CONNECTED_APP_CONSUMER_KEY
  5. sfdc.consumer.secret=CONNECTED_APP_SECRET
  • Connect to the Apache Unomi Karaf Shell using :
  1. ssh -p 8102 karaf@localhost (default password is karaf)
  • Deploy into Apache Unomi using the following commands from the Apache Karaf shell:
  1. feature:repo-add mvn:org.apache.unomi/unomi-salesforce-connectors-karaf-kar/${project.version}/xml/features
  2. feature:install unomi-salesforce-connectors-karaf-kar
  • You can then test the connection to Salesforce by accessing the following URLs:
  1. https://localhost:9443/cxs/sfdc/version
  2. https://localhost:9443/cxs/sfdc/limits

The first URL will give you information about the version of the connectors, so this makes it easy to check that theplugin is properly deployed, started and the correct version. The second URL will actually make a request to theSalesforce REST API to retrieve the limits of the Salesforce API.

Both URLs are password protected by the Apache Unomi (Karaf) password. You can find this user and password informationin the etc/users.properties file.

  • You can now use the connectors’s defined actions in rules to push or pull data to/from the Salesforce CRM. You canfind more information about rules in the Concepts and the Getting Started pages.

5.2.2. Hot-deploying updates to the Salesforce connector (for developers)

If you followed all the steps in the Getting Started section, you can upgrade the Salesforce connectors by using the following steps:

  • Compile the connectors using:
  1. cd extensions/salesforce-connectors
  2. mvn clean install
  • Login to the Unomi Karaf Shell using:
  1. ssh -p 8102 karaf@localhost (password by default is karaf)
  • Execute the following commands in the Karaf shell
  1. feature:repo-refresh
  2. feature:uninstall unomi-salesforce-connectors-karaf-feature
  3. feature:install unomi-salesforce-connectors-karaf-feature
  • You can then check that the new version is properly deployed by accessing the following URL and checking the build date:
  1. https://localhost:9443/cxs/sfdc/version

(if asked for a password it’s the same karaf/karaf default)

5.2.3. Using the Salesforce Workbench for testing REST API

The Salesforce Workbench contains a REST API Explorer that is very useful to test requests. You may find it here :

  1. https://workbench.developerforce.com/restExplorer.php

5.2.4. Setting up Streaming Push queries

Using the Salesforce Workbench, you can setting streaming push queries (Queries->Streaming push topics) such as thefollowing example:

  1. Name: LeadUpdates
  2. Query : SELECT Id,FirstName,LastName,Email,Company FROM Lead

5.2.5. Executing the unit tests

Before running the tests, make sure you have completed all the steps above, including the streaming push queries setup.

By default the unit tests will not run as they need proper Salesforce credentials to run. To set this up create aproperties file like the following one:

test.properties

  1. #
  2. # Licensed to the Apache Software Foundation (ASF) under one or more
  3. # contributor license agreements. See the NOTICE file distributed with
  4. # this work for additional information regarding copyright ownership.
  5. # The ASF licenses this file to You under the Apache License, Version 2.0
  6. # (the "License"); you may not use this file except in compliance with
  7. # the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. #
  17. sfdc.user.username=YOUR_USER_NAME
  18. sfdc.user.password=YOUR_PASSWORD
  19. sfdc.user.securityToken=YOUR_USER_SECURITY_TOKEN
  20. sfdc.consumer.key=CONNECTED_APP_CONSUMER_KEY
  21. sfdc.consumer.secret=CONNECTED_APP_SECRET

and then use the following command line to reference the file:

  1. cd extensions/salesforce-connectors
  2. mvn clean install -DsfdcProperties=../test.properties

(in case you’re wondering the ../ is because the test is located in the services sub-directory)