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
ECCLisaECCLisa 

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.

http://forums.sforce.com/sforce/board/message?board.id=NET_development&message.id=2627&query.id=5521#M2627

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
'-- NEW CODE START
Dim aNull(1) As String
aNull(0) = "CloseDate"
aNull(1) = "Credit_Report_Date__c"

objOpp.fieldsToNull = aNull
'-- NEW CODE END

'-- 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 -
Lisa
ChitraChitra
Hey ,

Did you set CloseDateSpecified field when updating ?

Thanks,
Chitra
ECCLisaECCLisa
No I did not. I will try that and update my post by the end of the week. Thank you!
ECCLisaECCLisa
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 -
Lisa
SuperfellSuperfell
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 ?
ECCLisaECCLisa
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 -
Lisa
SuperfellSuperfell
don't be encoruaged, that's a complete red herring in this case.
ECCLisaECCLisa
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!

Lisa