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
jtatejtate 

Dates in SalesForce

I'm modifying the Insert API sample application to insert an opportunity into SalesForce. I'm getting along just fine, but no matter what I try I cannot change the "closeDate" property. Which VB.Net data type must I use to get this to work properly? I've tried DateTime, and even writing a string in dateTime.iso8601 format, but I still get the "value not of required time dateTime.iso8601" error message. Is there sample code in VB on how to manipulate these types of fields?
jtatejtate
The above post was using the 2.0 API.

Rewriting my app using the 2.5 API, I get the following:
I create an sforce.Opportunity object, and set Name, AccountId, CloseDate, Type, StageName, Amount, LeadSource, NextStep, and Description, and then call sforce.SForceService.create() on the object. Create comes back with the following:

sforce.SaveResult
- errors {Length=1} sforce.Error()
- (0) {sforce.Error} sforce.Error
+ fields {Length=1} String()
message "Required fields are missing: [CloseDate]" String
statusCode REQUIRED_FIELD_MISSING sforce.StatusCode
id "" String
success False Boolean

The Opportunity object contains among other things:
-	data.Opportunity	sforce.Opportunity
CloseDate #12/31/2003# Date

Setting
Opportunity.CloseDateSpecified = True
fixes this problem.
DevAngelDevAngel

Hi jtate,

.Net handle certain types of data in a specific way for soap.  Date is one of those types.  Date cannot be null or nothing.  Go ahead and try to set it to nothing.  It won't work.  So, when attempting to create a soap message from the opportunity class, for instance, .Net doesn't serialize fields that are set to nothing.  But since you can't set a date to nothing .Net doesn't know whether you set the value or if it is the default value for a date.  To figure this out, .Net adds another field to you class called <field>Specified.  I didn't find this in any documentation, but you need to set this to true to indicate that you do indeed want .Net to serialize that date field.

That's all I got.