2
votes

I want to execute a SOQL by using Camel Salesforce component salesforce:query API for retrieving SObject Contact(s) by using AccountId. But it only return a DTO Contact which all fields are null. And I have debugged with Camel Salesforce component source code, and I found it got the Response with code 200.

BTW, does anyone know how to implement a dynamic SOQL, I found I cannot use ${body} in it, say, "sObjectQuery=SELECT LastName FROM Contact WHERE AccountID='${body}'"

  1. It is a simple maven project
  2. DTOs: Contact, Account have been generated by camel-salesforce-maven-plugin
  3. Other Camel Salesforce component REST API: salesforce:upsertSObject, salesforce:getSObjectWithId, salesforce:deleteSObjectWithId and salesforce:createSObject can be run and returned the correct results

Route:

from("direct:query")
    .to("salesforce:query?sObjectQuery=SELECT LastName FROM Contact&sObjectClass="+ Contact.class.getName())
    .process(exchange -> {
        Object body = exchange.getIn().getBody();
        System.out.println(body.getClass());
        System.out.println(body);
 });
ProducerTemplate template = camelCtx.createProducerTemplate();
Object obj = template.requestBody("direct:query", null, Object.class);

Actual Result: class com.salesforce.test.Contact {"Reporting_States__c":null,"Specialty__c":null}

Expected Result: return a QueryRecordsContact object which contains a fields of Contact List. (QueryRecordsContact is a DTO which was generated by Camel Salesforce maven plugin)

2
I think it should be a bug of Camel Salesforce Component, because I found other developer also encountered the similar issue camel.465427.n5.nabble.com/… - Dolphin

2 Answers

0
votes

Try rewriting your route like this:

    from("direct:query")
        .setHeader("sObjectQuery", simple("SELECT LastName FROM Contact WHERE id='${body}'"))
        .to("salesforce:query?sObjectQuery=&sObjectClass=" + QueryRecordsContact.class.getName())
        .process(exchange -> {
            Object body = exchange.getIn().getBody();
            System.out.println(body.getClass());
            System.out.println(body);
        });
  • you can place on sObjectQuery header the query you are interested in and build it dynamically there
  • the SF query returns a json containing a list of records, so you should pass QueryRecordsContact to the endpoint in order to make the right mapping
0
votes

Actually query return "done" , "totalSize" ,"records" as response .whatever you queried to salesforce query is in the records.To view this you have to add below line and their getter and setter in your class.

private List <yourClassName> records;

and then mapped list of object to appropriate class.

For more details:https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_query.htm