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 

Create opportunity from ASP.net

I was successful in using enterprise wsdl and create accounts cases etc from asp.net

But unable to create opportunity as the Close Date wont set and its a required field.

 

I used all combinations possible to set the .net date format to SFDC date format but it doenot work

Here is wat i tried on the .net side

 

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

                opp1.CloseDate = dt;

Best Answer chosen by Admin (Salesforce Developers) 

All Answers

kritinkritin

You need to use date value like this 

 

2005-10-08T01:02:03Z

 

See the apex_api

http://www.salesforce.com/us/developer/docs/api/apex_api.pdf

 

samrat.1985@lntinfotechsamrat.1985@lntinfotech

OK...this is my code
 EnterpriseWSDL.Opportunity opp1 = new EnterpriseWSDL.Opportunity();
              
               //  Set some fields on the account1 object. Name field is not set 
             
               //  Set some fields on the account2 object 
                opp1.AccountId = "0013000000ijgwgAAA";
                opp1.Name = "Semi Conductor";
             opp1.CloseDate = System.Convert.ToDateTime("2005-10-08T01:02:03Z");
                opp1.StageName = "Need Analysis";

EnterpriseWSDL.sObject[] opportunity = new EnterpriseWSDL.sObject[2];

               

                opportunity[0] = opp1;


               //  Invoke the create() call 

                try
                {


                    EnterpriseWSDL.SaveResult[] saveResults = service.create(opportunity);

                   //  Handle the results 

                    for (int i = 0; i < saveResults.Length; i++)
                    {
                       //  Determine whether create() succeeded or had errors 

                        if (saveResults[i].success)
                        {
                            // No errors, so retrieve the Id created for this record 

                            Console.WriteLine("An Opportunity was created with Id: {0}",
                                saveResults[i].id);
                            Console.ReadLine();
                        }
                        else
                        {
                            Console.WriteLine("Item {0} had an error updating", i);
                            Console.ReadLine();
                           //  Handle the errors 

                            foreach (EnterpriseWSDL.Error error in saveResults[i].errors)
                            {
                                Console.WriteLine("Error code is: {0}",
                                    error.statusCode.ToString());
                                Console.WriteLine("Error message: {0}", error.message);
                                                        }
                        }
                        Console.ReadLine();
                    }
                }
                catch (SoapException ex)
                {
                    Console.WriteLine(ex.Code);
                    Console.WriteLine(ex.Message);
                    Console.ReadLine();
                }

 

And the error is

 

UserId is:
00530000004Umi3AAC
Done

Item 0 had an error updating

Error code is: REQUIRED_FIELD_MISSING
Error message: Required fields are missing: [CloseDate]

kritinkritin

ClosingDate is not a Datetime type..its a Date type only.