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}'"
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)
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);
});
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.