Salesforce SOAP create record

2020-04-16 05:06发布

问题:

I have the following code to insert a record (I will be inserting 1000's). I get a successful insert but all of the numeric fields are EMPTY in salesforce. The one text field works fine ("Church of Randy") and appears in salesforce. Any ideas what I could be doing wrong?

  public void InsertTestRecord()
    {

        ChurchHist__c ch = new ChurchHist__c();


        ch.ChurchId__c = 9999;
        ch.ChurchName__c = "Church of Randy";
        ch.ReportYear__c = 2013;
        ch.ReportMonth__c = 08;
        ch.RegisteredMembers__c = 777;
        ch.ActiveMembers__c = 111;
        ch.InactiveMembers__c = 666;
        ch.UsersForMonth__c = 25;
        ch.ContribForMonth__c = 789.01;
        ch.ContribYTD__c = 200000.02;
        ch.AchContrib__c = 200000.00;
        ch.CcContrib__c = 0.02;
        ch.AchToCc__c = 0.12345;

        sObject[] s = new sObject[1];
        s[0] = ch;
        try
        {
            SaveResult[] saveResult = binding.create(s);

            if (saveResult[0].success)
            {
                Debug.Print("Success");
            }
            else
            {
                foreach (Error error in saveResult[0].errors)
                {
                    Debug.Print(error.statusCode.ToString());
                    Debug.Print(error.message);

                }
            }
        }
        catch (SoapException se)
        {
            Debug.Print(se.ToString());

        }

    }

回答1:

You need to set the specified flags, e.g. numeric property has an associated specified flag that controls if the .NET soap engine will actually send that property over the wire, unfortuantly the setter for the property does not automatically set the specified flag. e.g.

ch.ChurchId__c = 9999;
ch.ChurchId__cSpecified = true;
ch.reportyear__c = 2013;
ch.reportyear__cSpecified = true;

The specified flags are a "feature" of the .NET soap system for certain types. (numbers & dates IIRC).