2

I get an error when I try to set a checkbox with the Salesforce Partner API.

I have tried different combinations, but I get the error that an Object is required.

Confirmed__c is a checkbox and this is what I have tried

com.sforce.soap.partner.sobject.SObject record = new com.sforce.soap.partner.sobject.SObject();
record.setField("Confirmed__c",true);
record.setField("Confirmed__c",1);
record.setField("Confirmed__c","true");
record.setField("Confirmed__c","1");

This is the error I get when I compile

Incompatible type for method. Can't convert boolean to java.lang.Object.
record.setField("Confirmed__c",true);

I would appreciate it very much if someone could help me out with the correct way to accomplish this. I tried to find some examples on the web and I found one post, where it appears the first option above have worked, so not sure why I am getting this error?

https://stackoverflow.com/questions/12508026/how-to-disable-deactivate-a-salesforce-user-through-soap-api

Many Thanks, Kent

1 Answer 1

1

My Java is a bit rusty, but I think a boolean such as true is a primitive type.

Based on the error message:

Incompatible type for method. Can't convert boolean to java.lang.Object.

it appears the setField() method wants an instance of java.lang.Object.

So what you really want for the second parameter is an instance of Boolean (note the upper case B), which is a reference type.

In this case Java isn't doing the "boxing conversion" from boolean to Boolean for you implicitly.

Try:

record.setField("Confirmed__c", new Boolean(true));
1
  • Thanks Daniel, that worked like a charm. Much appreciated!
    – Kent
    Commented Oct 15, 2013 at 0:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .