# Camel SalesForce Kafka Connector PoC

## Running the Sink connector Locally

### 1. Starting up the connector
1. To create SalesForce application and get credentials, please follow this guide: https://github.com/apache/camel-examples/blob/main/examples/salesforce-consumer/README.adoc
You need `Client ID`, `Client Secret` and `Refresh Token`
2. The following env variables should be populated in docked-compose.yml:
- KAFKA_TOPICS: kafka topic to read messages from
- SF_INSTANCE: your salesforce login URL
- SF_CONSUMER_KEY: SalesForce Client ID from #1
- SF_CONSUMER_SECRET: SalesForce Client Secret from #1
- SF_REFRESH_TOKEN: SalesForce Refresh Token from #1
3. Start the connector
`docker compose up`

### 2. Configure SalesForce custom id fields
By default, the connector is configured to upsert `Contact` objects in SalesForce.
To upsert the data you need to create a custom field in the corresponding SalesForce object. 
In this example we are using `orchard_contact_id` field for `Contact` object. To create such 
field you need to:
1. Open `Setup >> Object Manager >> Select "Contact" object`
2. Open `Fields & Relationships >> New`
3. Set field label to `Orchard Contact Id` field name to `orchard_contact_id`.
4. Tick the "External ID" checkbox.

**Important note:** Despite the fact that you set your field name `orchard_contact_id`, the "real" field 
name, used by the SalesForce will be `orchard_contact_id__c`. You will need it in the next step. 

### 3. Sending the data to Kafka topic
You can send some test data to Kafka topic and see how the new `Contact` objects are being 
created and updated in SalesForce. Let's assume, that in step #1 you used `sf_sink_test_topic` as your 
Kafka topic to read messages from.
1. Open AKHQ Web UI: [https://dev-akhq.dev.theorchard.io/ui/dev/topic]()
2. Find your topic using the searchbox and doubleclick to open the topic page
3. Click the blue "+ Produce to topic" button
4. In the `Header` section add the header with external object id: 
\
   Key:`CamelHeader.orchard_contact_id__c`
   Value: `12345`
5. In the `Body` section insert the data that you want to upsert, for example:
```json
{
  "FirstName": "DemoUpsert",
  "LastName": "TestUpsert"
}
```
6. Click the blue "Produce" button
7. Check the "Contacts" page in your SalesForce instance, you should be able to see the new Contact created.
8. Send the message with the same `orchard_contact_id__c` value but change some data in the body. You should see 
an updated data for your SalesForce contact in a moment.
