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
cmarzillicmarzilli 

Using DateTime.Now for Event.ActivityDateTime Getting SOAP exception

I am using C# and I am trying to create a new Event in SalesForce.  I have done this a bunch of time in VB.
 
The only date I am setting is the activity date\time like so:
 

myEvent.ActivityDateTime = DateTime.Now;

And it sets to a value like: {5/5/2006 5:17:51 PM}

When I try to do my create (the event is the only object in sfObjects) :

binding.create( sfObjects );

I get an exception, not a nice SalesForce returned error but an exception that goes to a catch block:

"System.Web.Services.Protocols.SoapHeaderException: '2006-05-05' is not a valid value for the type xsd:dateTime\r\n at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)\r\n at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)\r\n at sForce.SforceService.create(sObject[] sObjects) in c:\\WINDOWS\\Microsoft.NET\\Framework\\v2.0.50727\\Temporary ASP.NET Files\\idsforce\\03c6c53b\\b241ba34\\App_WebReferences.xsyiie8g.0.cs:line 449\r\n at sfFunct.sfCreate(sObject sfObject) in c:\\Inetpub\\wwwroot\\IDsForce\\App_Code\\sfFunct.cs:line 124"

Now if I don't set an ActivityDateTime I do not get an exception but I do get an error back from the API saying that ActivityDateTime is a required field

Anyone have any ideas?  The stupid thing is the exact same code worked fine in VB.NET!

cmarzillicmarzilli

OK - I think this may have had something to do with VS 2005?

In my WSDL file I changed this line:

<xsd:element minOccurs="0" name="ActivityDateTime" nillable="true" type="xsd:dateTime" />

To:

<xsd:element minOccurs="0" name="ActivityDateTime" nillable="true" type="xsd:string" />

Now it works and SalesForce creates the Event.

However it doesn't seem like I should have to do this and I am a little worried that there may be repercussions to changing the WSDL in this manor.  Any help or advice would be very welcome.

 

Thanks!

SuperfellSuperfell
I've seen other reports that this happens intermittently, it seems to be a bug in .NET 2.0, If its repeatable, you should probably log a case with Microsoft.
cmarzillicmarzilli

Thanks Simon.  In case anyone else runs into this here is how I fixed it. First I changed the wsdl, as I mentioned, ActivityDateTime is defined as type xsd:string then I had to remove this line of code:

myEvent.ActivityDateTimeSpecified = true;

Not sure why.  When I set my ActivityDateTime I did so like this:

myEvent.ActivityDateTime = DateTime.Now.ToString( "s", System.Globalization.DateTimeFormatInfo.InvariantInfo );

And it worked.  All very strange.

cmarzillicmarzilli

Has anyone else every run into this issue?

My solution works but it's a pain because I have to edit the WSDL each time I update the web reference.  And frankly sometimes I forget and it breaks stuff!