Search code examples
javaapache-camelsalesforce

Unable to create camel salesforce endpoint


I am trying to connect to salesforce using Apache Camel salesforce component.

Here is a very simple route I am trying to start:

@Override
public void configure() throws Exception {
    from("salesforce:event/Case__e")
            .to("mock:end");
}

When trying to start it I am getting an obvious error saying I did not specify a client id:

Caused by: java.lang.IllegalArgumentException: clientId must be specified
at org.apache.camel.util.ObjectHelper.notNull(ObjectHelper.java:149) ~[camel-util-3.16.0.jar:3.16.0]
at org.apache.camel.component.salesforce.SalesforceLoginConfig.validate(SalesforceLoginConfig.java:238) ~[camel-salesforce-3.16.0.jar:3.16.0]

That makes perfectly sense as according to Camel docs clentId parameter must be specified. To address this I am specifying a clientId as below:

@Override
public void configure() throws Exception {
    from("salesforce:event/Case__e?clientId=xyz")
            .to("mock:end");
}

When trying to start the route this time I am getting a rather strange error complaining about clientId being an unknown parameter:

Failed to resolve endpoint: salesforce://event/Case__e?clientId=xyz due to: There are 1 parameters that couldn't be set on the endpoint.
Check the uri if the parameters are spelt correctly and that they are properties of the endpoint.
Unknown parameters=[{clientId=xyz}]

Not sure what I am doing wrong and how should I address this.

Thank you in advance for your inputs.


Solution

  • Your problem is related to the fact that clientId is a component option so it must be configured at the component level while you try to configure it like it was a query parameter / an endpoint option which cannot work.

    Depending on the runtime that you use, the way to configure a component may change but the idea remains the same.

    For example, assuming that you use an application.properties to configure your application, the configuration of your salesforce component would look like this:

    In application.properties

    # Salesforce credentials
    camel.component.salesforce.login-config.client-id=<Your Client ID>
    camel.component.salesforce.login-config.client-secret=<Your Client Secret>
    camel.component.salesforce.login-config.refresh-token=<Your Refresh Token>
    ...
    
    

    Here is a salesforce example https://github.com/apache/camel-examples/blob/main/examples/salesforce-consumer/