function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
CloudMikeCloudMike 

NULL Usage with API 6.0

I'm new to using the API so I need to clarify something for my own sanity.  As I understand it...

You cannot assign a NULL value directly to any sObject field like so:
    Dim acct as sforce.Account
    acct.ParentID = NULL 

so you must use the FieldsToNull approach which is something like this:
    acct.fieldsToNull = New String() {"ParentId"}

What if I have more than one field that needs setting to NULL, can I do the following:
    acct.fieldsToNull = New String() {"ParentId"}
    acct.fieldsToNull = New String() {"Website"}

or do I have to do this:
    acct.fieldsToNull = New String() {"ParentId","Website"}

If the second is the case, its ridiculous!  Do you know what kind of a headache it is to have to loop through an entire datarow just looking for NULL values (which can differ everytime), then have to create this array and then have to assign all the non Null values? 

And fieldsToNull only works when using binding.update, correct?  So if I need to set fields to NULL when creating an object do I just skip them?  If so, that's an even bigger pain!  What are the odds that someone will decide to alter the functionality of the API so the following works more efficiently?
    For j As Integer = 0 To drFiltered.Length - 1
       account = New sforce.Account
       With account
           .Name = drFiltered(j).Item("Name")
           .Type = drFiltered(j).Item("Type")
           .ParentId = drFiltered(j).Item("ParentID")    'may or may not be NULL
           .Phone = drFiltered(j).Item("Phone")    'may or may not be NULL
           .Fax = drFiltered(j).Item("Fax")    'may or may not be NULL
           .Website = drFiltered(j).Item("Website")    'may or may not be NULL
       End With
       accs(j) = account
    Next
    Dim sr() As sforce.SaveResult = _binding.create(accs)

 

Sorry, but I'm incredibly frustrated with this!

Message Edited by SatelliteMike on 07-25-2005 10:51 AM

Message Edited by SatelliteMike on 07-25-2005 10:53 AM

CloudMikeCloudMike

Just a follow-up.  I resolved the Create approach by simply ignoring the NULL fields and let me be set to whatever default values may apply. 

However, I would still like to have someone clarify my understanding of the Update approach.

Thanks in advance!

GlennWGlennW
Mike;

Your second option on the NULL on update is correct. It may seem strange but you'll find in the future that there is an importance on NULL values vs empty strings.

Try this..... Create a wrapper class around the binding object for your own update class that you can simply feed the fieldnames, fieldvalues and nullfields to your class and have it build the sobjects and post them when required.

GlennW
CloudMikeCloudMike
Glenn, thanks for the reply but I resolved the issue through painful trial and error.