tree: 227f2f5b572219d9a36bb304b1c816c68f81a031 [path history] [tgz]
  1. src/
  2. .gitignore
  3. LICENSE-SALESFORCE.txt
  4. LICENSE.txt
  5. NOTICE.txt
  6. pom.xml
  7. README.md
components/camel-salesforce/camel-salesforce-component/README.md

Camel Salesforce component

This component supports producer and consumer endpoints to communicate with Salesforce using Java DTOs. There is a companion maven plugin camel-salesforce-plugin that generates these DTOs.

Developing the Camel Salesforce component

Running the integration tests

Note: These instructions are only for running integration tests, they use permissions and IP restrictions that should be reconsidered for production use.

Note: Running the tests you will quickly use up your API allowance, 15,000 requests/day in the free developer account. Make sure that you won't deny your other applications/users access by running them. Scratch orgs are preferable as they have a more generous limit of 5,000,000 requests/day.

In order to run the integration tests you need a Salesforce Developer account. You can get a Salesforce Developer account by visiting developer.salesforce.com and sign up for one.

As of 2.19 we maintain any Salesforce setup needed to run the integration tests in the it/resources/salesforce directory, the files there are generated by the Salesforce Migration Tool that you can freely download from Force.com Migration Tool. This is an Apache Ant extension, by which you get additional Ant tasks to retrieve and to upload configuration, classes, schema changes and such. Download it and place the ant-salesforce.jar from the downloaded ZIP file into components/camel-salesforce/it/resources/migration-tool/.

We have integrated Salesforce Migration Tool into the Maven integration-test lifecycle phase and it should run and update your Salesforce instance to a state capable of running integration tests. Start by creating test-salesforce-login.properties in the parent Maven module (camel-salesforce), you can use test-salesforce-login.properties.sample as reference.

Note: Remember that if you do not relax IP restrictions, by default you'll need to append the security token on the password you place in the test-salesforce-login.properties file.

Before running the tests for the first time run the migration by invoking Maven from the camel-salesforce-component Maven module directory:

$ mvn -Pintegration resources:copy-resources@copy-test-salesforce-login-properties \
  resources:copy-resources@set-connected-app-client-id antrun:run@setup-salesforce-instance

This will create a Connected App with predefined Consumer Key (the one mentioned in the comment one in test-salesforce-login.properties.sample) and Consumer Secret (clientSecret) with the name of CamelSalesforceIntegrationTests.

Note that this deployment is run every time you run the integration tests by issuing from the camel-salesforce-component Maven module directory:

$ mvn -Pintegration verify

However, once the deployment is successful, subsequent deployments are redundant, but harmless as it is an idempotent operation.

If you need any custom fields, Apex classes or other configuration changes done, make sure to download them using the Salesforce Migration Tool and include them in it/resources/salesforce directory.

After the initial successful deployment, in salesforce go to Setup > App Manager, find the CamelSalesforceIntegrationTests app and click View. Copy the Consumer Key and Consumer Secret values into salesforce.client.id and salesforce.client.secret respectively.

The deployment includes a permission set called Hard Delete Permission Set which contains the Hard Delete permission as well as field-level permissions needed to run the integration tests. You can assign this permissions set to the user you use to run tests.

It‘s also recommended to set email deliverability to System Email Only so you don’t receive loads of approval emails when the tests run. This can be found in Setup > Email > Deliverability.

If your org contains Duplicate Rules for Objects the integration tests use, they could cause the tests to fail. If this is the case, deactivating the rules is recommended.

If your tests cannot be run alongside other tests you can use @Standalone to mark them as such.

Manual Salesforce instance setup for integration tests

This is included for those that wish to setup the Salesforce instance manually for integration tests. It could also help to double-check your setup.

Besides that account you'll need a test user account that has Bulk API Hard Delete permission set. You can create one by going to My Developer Account (link from developer.salesforce.com). Under Administer expand Manage Users and select Profiles find System Administrator profile and select Clone. Use System Administrator With Hard Delete as the profile name, and after saving under Administrative Permissions click edit and tick Bulk API Hard Delete and save. Next, create a new user under Administer expand Manage Users and select Users and then click on New User. Fill in the required fields, and select Salesforce for User License and newly created profile for Profile. You get two user Salesforce licenses so the newly created user will put you at a maximum.

Install the Warehouse package, tested with Spring 2013 (version 1.2) that can be installed from the https://login.salesforce.com/packaging/installPackage.apexp?p0=04ti0000000Pj8s, and make the following modifications manually:

  • add custom field Description of type Text with maximum length of 100 on the Merchandise object
  • add custom required field Total_Inventory of type Number with maximum length of 18 without default value on the Merchandise object
  • add custom field Shipping_Location of type GeoLocation on the Account object
  • add custom field Units_Sold of Number type with maximum length of 18 on the Line_Item object
  • delete custom fields Quantity, Invoice, Line_Item_Total from the Line_Item object
  • delete custom field Quantity from the Merchandise object, you will need to delete dependencies (ApexClass and Visualforce Page)
  • create new ApexClass named MerchandiseRestResource with the content of MerchandiseRestResource.apxc
  • deactivate the Contact Duplicate Rule in salesforce configuration
  • add Account to selected entities for change data capture in the Integrations/Change Data Capture menu
  • add the Hard Delete Permission Set to the CamelSalesforceIntegrationTests Connected App (e.g. Setup/ConnectedApp/ManagePermissionSets)

You'll need to access a Merchandise record and run a Test Report in order for them to appear in Recent Items and Recent Reports. Do this by accessing Warehouse application from the menu in the top right, and selecting Merchandise click Go! (preselected is View: All) and click on the single Merchandise item available. Next go to Reports and select and run Test Report from Test Reports. This is needed by the integration tests as they access recent items and recently run reports.

Create Camel connected application by selecting under Apps in Build and Create sections by clicking New in Connected Apps section. Fill in the required fields and in the API (Enable OAuth Settings) section thick Enable OAuth Settings and move all scopes from Available OAuth Scopes to Selected OAuth Scopes. For Callback URL you can use any URL it‘s not needed by the REST API used by the Camel Salesforce component. Make note of Consumer Key and Consumer Secret, or if your partner provide just Consumer Refresh Token you’ll need to specify them in test-salesforce-login.properties, more on that below.

Next enable relaxed IP restrictions, by editing the policy of the Camel connected application in Connected Apps under Administer and Manage Apps pick Relax IP restrictions for IP Relaxation.

Create test-salesforce-login.properties in camel-salesforce directory (one up from the directory this file resides in) with the content:

clientId=<Consumer Key of the `Camel` connected App>
clientSecret=<Consumer Secret of the `Camel` connected app>
refreshToken=<Consumer Refresh Token of the `Camel` connected app>
userName=<Username of the user with the `System Administrator With Hard Delete` profile>
password=<Password of the above user>
loginUrl=https://login.salesforce.com/
report.0=Test_Report