I'm trying to create an object of SObject
class and then setting its type to Lead
and setting one of the fields for Email
.
Eventually, I want to pass this object in findDuplicates()
method. But the compiler says that it cannot resolve methods setType
and setField
for given object. It's failing at the compilation. Following is the code:
SObject[] inputSObjectArray = new SObject[1];
// Instantiate an empty Java SObject
SObject searchCriteria = new SObject();
// Set its type to Lead.
searchCriteria.setType("Lead");
// Set Email field.
searchCriteria.setField("Email", "[email protected]");
// Add the sObject to the input array
inputSObjectArray[0] = searchCriteria;
Connection.getInstance().getConnection().setDuplicateRuleHeader(false, true, false);
FindDuplicatesResult[] callResults = null;
try {
callResults = Connection.getInstance().getConnection().findDuplicates(inputSObjectArray);
} catch (ConnectionException e) {
e.printStackTrace();
}
if (callResults != null && callResults.length > 0) {
// print results
}
Following is the compilation error:
Error:(223, 23) java: cannot find symbol
symbol: method setType(java.lang.String)
location: variable searchCriteria of type com.sforce.soap.enterprise.sobject.SObjectError:(225, 23) java: cannot find symbol
symbol: method setField(java.lang.String,java.lang.String)
location: variable searchCriteria of type com.sforce.soap.enterprise.sobject.SObject
I'm referring to the sample code given for Java in SalesForce documentation. Ref: https://resources.docs.salesforce.com/206/latest/en-us/sfdc/pdf/apex_api.pdf
Update: I've got the enterprise.wsdl from my SalesForce Admin. I generated the enterprise.jar using the guidelines from here. And I've included this external jar in my Java project. So I'm assuming all the Core classes / methods should be available for use to me, which is not happening.