+ Start a Discussion

Setting a checkbox value - amazed

I am amazed on how difficult I find it to set a checkbox to it's value.
Using a simple x = true on a custom field (checkbox) on 1 custom object, and I get nothing correct.
code is c#
        private static void createLicense()
            if (!loggedIn())

                //Create an account object to send to the service
                sforce.OptiTex_License__c license = new sforce.OptiTex_License__c();
                //Set several properties
                license.X1_Marker__c = true;
                license.X2_Grading__c = false;


                // Add the account to an array of SObjects
                sforce.sObject[] records = new sforce.sObject[] { license };

                // Invoke the create call, passing in the account properties
                // and saving the results in a SaveResult object
                sforce.SaveResult[] saveResults = binding.create(records);

                // Access the new ID
                String newID = saveResults[0].id;
            catch (Exception e)
                Console.WriteLine(e.Message + "\n" + e.StackTrace);

 I tried both true or false , 0, 1 (which offcourse failed cause it's a boolean and not int field.
any help is appreciated thanks.
license.foo__c = true;
license.foo__cSpecified = true;
Thanks Simon,
fixed. However, since this is not the most logical way to set a checkbox, howbout a minor update?
or a simple note in the help on it. I have done my RTFM and found nothing about it in the help.
BOYA !!!
I agree with this comment, because I found out about this '...specified=true' by looking in the object and just setting it to true to see if it would work.
I'll see about getting it noted in the docs, but its very much a .NET speciifc issue. (if you look in the WSDL, you'll see we don't set the specified flags, that something that .NET adds in).
Just to try and clarify this, the fooSpecified flag, is nothing to do with Salesforce.com, its a .NETism that's a hangover from handling value types in .NET 1.x. I've complained many times to MSFT that the generated property setter should set the specified flag as well, but the more people that raise this, the more likely they'll do something about it.
I also have a project on the backburner to provide an alternative to wsdl.exe which would generate this modified setter code.