2

I am using force toolkit for .net to get contact fields. I make a soql query like:

SELECT Id, FirstName, LastName, Salutation FROM Contact

One of my contact has a salutation field set to Mr. like this screenshot:

salesforce web page

After I edit the contact, the query result however, returns a null salutation field in the json string:

enter image description here

Question:

What am I missing to successfully get (or set) the contact salutation field?

Edit:

After a few hours, I tested the same query. Finally I got the salutation field Mr. listed in the same contact record.

Very strange. Might be a Salesforce related problem?

3
  • 1
    Have you tried with the most recent api version (later than v36.0)?
    – Jayant Das
    Commented Jan 4, 2019 at 4:19
  • 1
    I just verified with v36.0 and later and could get the desired results, i.e., could get Salutation field. You may like to verify if the data as in screenshot you have here was saved or not, i.e., if the record was saved with theSalutation value or not.
    – Jayant Das
    Commented Jan 4, 2019 at 4:31
  • @JayantDas I checked the reoird. It surely has a salutation value Mr. saved.
    – Dia
    Commented Jan 4, 2019 at 6:26

1 Answer 1

2

It seems unlikely that you are being impacted by the SOQL Query - Not returning salutation field in some scenarios known issue in this case as you aren't using a relationship query to retrieve the Contacts Salutation field.

It's more likely that either:

  1. The salutation field hasn't actually been updated successfully in Salesforce, or
  2. Something is caching the prior value.

I used the following console application to verify that the Salutation can be changed and then retrieved successfully using the .NET toolkit.

using Salesforce.Common;
using Salesforce.Common.Models.Json;
using Salesforce.Force;
using System;
using System.Net;
using System.Threading.Tasks;

namespace ConsoleApplication21
{
    class Program
    {
        const string clientId = "ABCDEFiTxZANhwHQt0.omitted.pQqhw5m7nxK6aBx1234567890";
        const string clientSecret = "12345678901234567890";
        const string username = "[email protected]";
        const string password = "omitted";

        static void Main(string[] args)
        {
            MainAsync().Wait();
        }

        static async Task MainAsync()
        {
            try
            {
                const int SecurityProtocolTypeTls11 = 768;
                const int SecurityProtocolTypeTls12 = 3072;
                ServicePointManager.SecurityProtocol |= (SecurityProtocolType)(SecurityProtocolTypeTls12 | SecurityProtocolTypeTls11);

                var auth = new AuthenticationClient();
                await auth.UsernamePasswordAsync(clientId, clientSecret, username, password);

                var client = new ForceClient(auth.InstanceUrl, auth.AccessToken, auth.ApiVersion);

                string newSalutation = "Mr.";

                var contact = new Contact() {Salutation = newSalutation };
                string contactId = "0037000001ngFB6AAM";

                SuccessResponse updateResponse = await client.UpdateAsync("Contact", contactId, contact);

                System.Diagnostics.Debug.Assert(updateResponse.Success);

                var updatedContacts = await client.QueryAsync<Contact>(string.Format("SELECT ID, Salutation from Contact where ID = '{0}'", contactId));
                foreach(Contact updatedContact in updatedContacts.Records)
                {
                    System.Diagnostics.Debug.Assert(updatedContact.Salutation == newSalutation);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.Fail(ex.Message);
            }
        }
    }

    public class Contact
    {
        public string Id { get; set; }
        public string Salutation { get; set; }
    }
}

With that I was able to successfully change the Salutation from Dr. to Mr. and back again.

1
  • Thank you. The value might be cached for this record? Hope salesforce fix this problem soon.
    – Dia
    Commented Jan 7, 2019 at 2:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .