Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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?

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

Many Thanks, Kent

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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));
share|improve this answer
    
Thanks Daniel, that worked like a charm. Much appreciated! –  Kent Oct 15 '13 at 0:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.