+ Start a Discussion

Clearing Date/Time Field (VB.NET)

I referred to the following post regarding clearing a date field and changed it for VB but I cannot seem to get the date field to clear.


Here is a subset of my test code:

'-- Create Opportunity Record
Dim objOpp As New Opportunity
objOpp.Id = sMyID
objOpp.Name = "Testing"

'-- Specify fields to null
Dim aNull(1) As String
aNull(0) = "CloseDate"
aNull(1) = "Credit_Report_Date__c"

objOpp.fieldsToNull = aNull

'-- Add this Opportunity to the array to send to SF
Dim aobjOpps() as sObject
aobjOpps(0) = objOpp

'-- Call Update
Dim aobjSaveResult() As SaveResult = Nothing
aobjSaveResult = myBinding.update(aobjOpps)

This is a trimmed down version of the acutal code. Everything is working just fine for updates and has been for months. I've simply attempted to add the logic to null out certain fields. Here's what happens/doesn't happen:

- The code runs without error
- The update occurs
- Save result reflects success
- The fields are not nulled

I'm sure I'm just missing something simple but I can't figure out what!

Thank you for any insight -
Hey ,

Did you set CloseDateSpecified field when updating ?

No I did not. I will try that and update my post by the end of the week. Thank you!
Thank you for the suggestion Chitra. I'm closer....but still no cigar. I've indicated the date fields are specified, but now when the update runs, my saveresult contains a failure. The error message is:

CloseDate: invalid date: Sat Jan 01 00:00:00 GMT 1

Help SimonF!!

Thank you -
CloseDateSpecified should be false

other than that, can't see anything wrong, are you sure the fieldsToNull is not getting wiped out further on in the code you don't show ?
It's the last thing I'm doing before I'm sending the object to my update function. I also ensured I'm not setting it to something else prior to setting the fields to null. I'm encouraged by the fact that the error is "invalid date: Sat Jan 01 00:00:00 GMT 1" because that sure looks like an attempt to set the date to null. Any other thoughts or ideas??

Thank you Simon -
don't be encoruaged, that's a complete red herring in this case.
OK! All is fine! I re-read the posts here and realized I was doing the usual, "myfield_Specified = true" when it should have been FALSE. Syntax should be:

Dim aNull(1) As String
aNull(0) = "Credit_Report_Expiration_Date__c"
aNull(1) = "Credit_Report_Date__c"
objLoan.Credit_Report_Expiration_Date__cSpecified = False
objLoan.Credit_Report_Date__cSpecified = False
objLoan.fieldsToNull = aNull

Thank you for explicitly stating that! Yeah, it was specified, but it was specified WRONG!

Thanks Simon!