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
samrat.1985@lntinfotechsamrat.1985@lntinfotech 

Please help its urgent...I am trying to create

...opportunity from .net using enterprise WSDL.

But it wont create due to Close date format issues.

 

i useed

opp1.CloseDate=System.convert.ToDateTime("23/03/2011").ToDate;

 

what is the correct way...i have been banging my head on this for long now :(

Best Answer chosen by Admin (Salesforce Developers) 
JPClark3JPClark3

1) Make sure you have this:   

opp1.CloseDateSpecified = true;

 

2) Also try changing the project target platform to x86 instead of any CPU.

 

 

3) if your date string is coming in from an unknown source:

 

 

//val is the input date string
DateTime dtfromstr;
if (DateTime.TryParse(val, out dtfromstr))
    opp1.CloseDate = dtfromstr;
    opp1.CloseDateSpecified = true;
else
    opp1.CloseDateSpecified = false;  //or you can set DateTime.Now.Date;

 

 

 

All Answers

SimplySfdcSimplySfdc

try to use YYYY-MM-DD format

 

 

sq

samrat.1985@lntinfotechsamrat.1985@lntinfotech

I tried using

 

 

 

DateTime dt = DateTime.ParseExact(DateTime.Now.ToString(), "YYYY-MM-DD", CultureInfo.InvariantCulture);

opp1.CloseDate = dt;

 

in my .net code but it wont work......

JPClark3JPClark3

Have you read Simon Fell's post on Date formats?

 

DateTime Parsing Issues with .NET

 

samrat.1985@lntinfotechsamrat.1985@lntinfotech

Yes i saw this post.....

but it didnt help me... is there anything else?

JPClark3JPClark3

1) Make sure you have this:   

opp1.CloseDateSpecified = true;

 

2) Also try changing the project target platform to x86 instead of any CPU.

 

 

3) if your date string is coming in from an unknown source:

 

 

//val is the input date string
DateTime dtfromstr;
if (DateTime.TryParse(val, out dtfromstr))
    opp1.CloseDate = dtfromstr;
    opp1.CloseDateSpecified = true;
else
    opp1.CloseDateSpecified = false;  //or you can set DateTime.Now.Date;

 

 

 

This was selected as the best answer
samrat.1985@lntinfotechsamrat.1985@lntinfotech

Thanks a ya its the boolea set CloseDateSpecified that i missed... it worked fine now :D