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
rschenkelrschenkel 

Custom field created as null

I created a custom field in Account.  I redownloaded my WSDL and the field show up without problem.  However, when I run the create function the custom field gets created as null instead of the value I supplied.

 

Any help would be appreciated.

rschenkelrschenkel

Using upsertResult instead of create works.

SuperfellSuperfell

What toolkit are you using? what's your code ?

rschenkelrschenkel

        private bool UpdateAccount(double dCorpCode, string strName, string strAddress1, string strAddress2, string strCity, string strProvince, string strCountry, string strPostalCode)
        {
            try
            {
                Account[] accounts              = new Account[1];
                accounts[0]                     = new Account();
                accounts[0].ExId__c             = dCorpCode.ToString();
                accounts[0].AccountNumber       = dCorpCode.ToString();
                accounts[0].Name                = strName;
                if (String.IsNullOrEmpty(strAddress2) == true)
                    accounts[0].BillingStreet = strAddress1;
                else
                    accounts[0].BillingStreet = strAddress1 + "\n" + strAddress2;
                accounts[0].BillingCity         = strCity;
                accounts[0].BillingState        = strProvince;
                accounts[0].BillingCountry      = strCountry;
                accounts[0].BillingPostalCode   = strPostalCode;

                UpsertResult upsertResult = _sforceService.upsert("ExId__c", accounts)[0];
                if (upsertResult.success == false)
                {
                    // TODO: Log error
                    Error[] errors = upsertResult.errors;
                    return false;
                }

                return true;
            }
            catch (Exception e)
            {
                // TODO: Log error
                return false;
            }
        }

SuperfellSuperfell

The only custom field you're setting is extId__c, which must have a value if the upsert call is succeeding.

rschenkelrschenkel

Thanks Simon.  That was the code that I actually got working.  I was looking for the old create call but could not find it.  I was not able to create or update custom fields using create or update.  However, the code above does work with upsert.