+ Start a Discussion
saariko.ax241saariko.ax241 

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#
Code:
        private static void createLicense()
        {
            if (!loggedIn())
                return;

            try
            {
                //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;

                //license.X4_Light_version__c.

                // 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;
                Console.WriteLine(newID.ToString());
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message + "\n" + e.StackTrace);
                return;
            }
        }

 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.
SuperfellSuperfell
license.foo__c = true;
license.foo__cSpecified = true;
saariko.ax241saariko.ax241
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 !!!
smillssmills
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.
saariko.ax241saariko.ax241
SuperfellSuperfell
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).
SuperfellSuperfell
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.