Reply
Super Contributor
benjasik
Posts: 848
0
Accepted Solution

Why is my date/number/boolean being ignored for create and update?

The code below runs fine and prints the ID of the newly created object, but when I look in the app, AnnualRevenue is blank!

sforce.Account newAcc = new sforce.Account();
newAcc.Name = "Test Account";
newAcc.AnnualRevenue = 10000;
sforce.SaveResult [] sr = svc.create ( new sforce.sObject[] { newAcc } );
if(sr[0].success)
{
Console.WriteLine("new id of account is {0}", sr[0].id); } else {
Console.WriteLine("error creating account {0}", sr[0].errors[0].message);
}


What's happening is that for field type's that do not support being null in .NET, the generated .NET code includes an additional property that indicates if it should send the value. Unfortuanly even if you explicitly set a value, the property that says to send the value doesn't get set. You need to also set that property as well. These properties have "Specified" appended to the property name they apply to, so the above example should be

sforce.Account newAcc = new sforce.Account();
newAcc.Name = "Test Account";
newAcc.AnnualRevenue = 10000;
newAcc.AnnualRevenueSpecified = true;
sforce.SaveResult [] sr = svc.create ( new sforce.sObject[] { newAcc } );
if(sr[0].success)
{
Console.WriteLine("new id of account is {0}", sr[0].id); } else {
Console.WriteLine("error creating account {0}", sr[0].errors[0].message); }
}

If you run this revised version, you'll see the AnnualRevenue value in the application. Properties of type DateTime, bool, int and double all have these additional specified flags.
Benji Jasik
Senior Director Product Management
Developer Network Blog: http://blog.sforce.com
Regular Contributor
zak
Posts: 109
0

Re: Why is my date/number/boolean being ignored for create and update?

Looking at the .NET 2.0 beta, this doesn't get any improvements, see http://www.pocketsoap.com/weblog/2004/07/1461.html

There's also an open suggestion in the new MSDN product feedback center to do some improvements in this area, if you've run into this problem, you might want to add your feedback.

http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=bb1331f3-6b2c-4d3e-851a-5...

 

Cheers

Simon

 

Regular Contributor
HaroldH
Posts: 71
0

Re: Why is my date/number/boolean being ignored for create and update?

[ Edited ]
How do you specify that a value is specified, when using the Partner WSDL?

I'm getting this result (boolean field not set to the specified value) when attempting to create or update a custom field on the Account object. (.NET 1.1)

Message Edited by HaroldH on 05-24-2005 11:48 AM

Moderator
SimonF
Posts: 7,975
0

Re: Why is my date/number/boolean being ignored for create and update?

This doesn't apply to the Partner WSDL, only the enterprise WSDL. In the Partner WSDL you have direct control over the element in the request, via the Any property on the sObject.
Cheers
Simon
docs | blog | twitter
Contributor
jamesob5
Posts: 3
0

Re: Why is my date/number/boolean being ignored for create and update?

I'm having the same issue using .Net and the enterprise wsdl. All numbers/boolean/date fields are ignored.No errors and all text/string fields go thru.

 


using (SforceService sfdc = new SforceService())
        {
            LoginResult lr = sfdc.login(ConfigurationSettings.AppSettings["NextGen.SalesForce.UserName"], ConfigurationSettings.AppSettings["NextGen.SalesForce.Password"]);
            if (!lr.passwordExpired)
            {
                bool blnLocated = false;
                sfdc.Url = lr.serverUrl;
                sfdc.SessionHeaderValue = new SessionHeader();
                sfdc.SessionHeaderValue.sessionId = lr.sessionId;

                QueryResult qrLead = new QueryResult();
                QueryResult qrContact = new QueryResult();
                QueryResult qr = new QueryResult();
                sfdc.QueryOptionsValue = new QueryOptions();
                sfdc.QueryOptionsValue.batchSize = 250;
                sfdc.QueryOptionsValue.batchSizeSpecified = true;
                int pID = 31;
                qrLead = sfdc.query("select id, IsConverted, ConvertedContactId, Do_you_currently_have_an_electronic_heal__c, Num_Providers__c, Company_name__c from Lead where NGC_ProfileID__c='" + pID.ToString() + "'");
                if (qrLead.size > 0)
                {
                    qr = qrLead;
                    blnLocated = true;
                }

                if (blnLocated)
                {
                    for (int i = 0; i < qr.records.Length; i++)
                    {
                        Lead lead = (Lead)qr.records[i];
                        string strID = lead.Id;
                        sObject[] UpdateLink = new sObject[1];
                        if ((bool)lead.IsConverted)
                        {
                            //Contact uContact = new Contact();
                            //uContact.Id = lead.ConvertedContactId;
                            //uContact.Company_name__c = CompanyName.Length > 50 ? CompanyName.Substring(0, 50) : CompanyName;
                            //uContact.Position__c = Position.Length > 30 ? Position.Substring(0, 30) : Position;
                            //uContact.Company_URL__c = CompanyURL;
                            //uContact.Industry__c = IndType.Length > 50 ? IndType.Substring(0, 50) : IndType;
                            //if (PositionDesc != null)
                            //{
                            //    uContact.Position__c = PositionDesc.Length > 30 ? PositionDesc.Substring(0, 30) : PositionDesc;
                            //}
                            //UpdateLink[0] = uContact;
                        }
                        else
                        {                           
                            Lead uLead = new Lead();
                            uLead.Id = strID;
                           
                            uLead.First_name__c = "James"; //Works
                            uLead.Title = "Web Developer"; //Works
                            uLead.Position__c = "Web Developer"; //Works
                            uLead.Login_Enabled__c = true; // Ignored
                            uLead.Do_you_currently_have_an_electronic_heal__c = false; // Ignored
                            uLead.LeadSource = "Cold"; //Works
                            uLead.Num_Providers__c = 50; // Ignored
                            uLead.Practice_Specialties__c = "Anesthesiology; Asthma & Allergy"; //Works
                            UpdateLink[0] = uLead;                            
                        }
                        SaveResult[] sr = sfdc.update(UpdateLink);

                        for (int j = 0; j < sr.Length; j++)
                        {
                            if (sr[j].success)
                            {
                                //Console.Write(System.Environment.NewLine +
                                //"An account was created with an id of: " + sr[j].id);
                            }
                            else
                            {
                                //there were errors during the create call, go through the errors
                                //array and write them to the screen
                                for (int x = 0; i < sr[j].errors.Length; x++)
                                {
                                    //get the next error
                                    Error err = sr[j].errors[i];
                                    Console.WriteLine("Errors were found on item " + j.ToString());
                                    Console.WriteLine("Error code is: " + err.statusCode.ToString());
                                    Console.WriteLine("Error message: " + err.message);
                                }
                            }
                        }
                    }
                }
            }
        }

 

Moderator
SimonF
Posts: 7,975
0

Re: Why is my date/number/boolean being ignored for create and update?

See the first post it has the answers.
Cheers
Simon
docs | blog | twitter
Regular Contributor
rschenkel
Posts: 12
0

Re: Why is my date/number/boolean being ignored for create and update?

Hi Simon,

Did you mean the post of your blog?  From that I get I should do this?

accounts[0].Billing_Info_Supplied_rdp__c = bBillingInformationSupplied;
accounts[0].Billing_Info_Supplied_rdp__cSpecified = bBillingInformationSupplied;
 
Unfortunately that did not correct the problem.

Contributor
Paladyr
Posts: 8
0

Re: Why is my date/number/boolean being ignored for create and update?

First time I needed to post a question and here is the answer. Awesome!