In date type field value not bind from using webservice c# code - Answers - Salesforce Trailblazer Community
Trailblazer Community
Ask Search:
Tony DiPiazzaTony DiPiazza 

In date type field value not bind from using webservice c# code

In my opportunity object i have a field called CloseDate as type Date. Using webservice i am creating opportunity.

My c# code to create oppportunity is as follows

 sforce.Opportunity Contribution = new sforce.Opportunity();

            Contribution.RecordTypeId = "012400000005T5P";
            Contribution.Entity_Household_or_Org__c = SFEntityId;
            Contribution.Contact__c = SFRespId;
            Contribution.Name = "Sample";
            Contribution.CloseDate = DateTime.Parse(DateTime.Now.Date.ToShortDateString());
            Contribution.StageName = "Posted";

            Contribution.Total1__c = double.Parse(txtDonation.Text);
            Contribution.Credit_Card_Number__c = txtCreditcard.Text;
            Contribution.Expiration_Month__c = cmbMonth.SelectedValue;
            Contribution.Expiration_Year__c = cmbYear.SelectedItem.Text;         


            sObject[] SFContribution = new sObject[2];
            SFContribution[0] = Contribution;
            SaveResult[] saveResults1 = binding.create(SFContribution);

after executing the code saveResults1  object throw error like Required field CloseDate missed.
  in the time of execution Contribution.CloseDate have value as
10/15/2009 6:45:06 AM


give the solution

Thanks in advance.




Sunil KeshariSunil Keshari
Tony,

Developer forum is the best place to get answers for these questions.

http://boards.developerforce.com/sforce/?category.id=developers
Chris O DaviesChris O Davies
Yes CloseDate might have a value but the format is different in Apex 

Example is Year,month,day:
  • YYYY-MM-DDThh:mm:ss+hh:mm
  • YYYY-MM-DDThh:mm:ss-hh:mm
  • YYYY-MM-DDThh:mm:ssZ
  • 1999-01-01T23:01:01+01:00
  • 1999-01-01T23:01:01-08:00
  • 1999-01-01T23:01:01Z
You can use the following in your apex class to format the value:
DateTime dt = DateTime.valueOf(YourdateTime); // For Date Time
Date d = Date.valueOf(Yourdate); // For Date