I have the following C# code:-

            string query = @"select Unique_Contact_ID__c"
                        + ",Account.Account_Unique_ID__c"
                        + ",FirstName"
                        + ",LastName"
                        + ",Salutation"
                        + ",Phone"
                        + ",HomePhone"
                        + ",MobilePhone"
                        + ",Email"
                        + ",Title"
                        + ",Fax"
                        + ",Notes__c"
                        + ",MailingStreet"
                        + ",MailingCity"
                        + ",MailingState"
                        + ",MailingPostalCode"
                        + ",MailingCountry"
                        + ",Account.Name"
                        + ",LastModifiedDate"
                        + ",IsDeleted"
                        + ",Main_Accounts_Contact__c"
                        + ",Main_Sales_Contact__c"
                        + ",Company_Type__c"
                        + " from Contact "
                        + " ORDER BY Id LIMIT 10";

            var contacts = new List<Contact>();

            log.LogMessage("Running query to get data from salesforce");

            var results = await client.QueryAsync<Contact>(query);


Note the two columns in the query that have a dot(.) in them - Account.Account_Unique_ID__c and Account.Name

Contact is a .NET class. I can't have dot(.)'s in my class property names so when this code executes all the other properties of the class are populated beautifully but the two with dots are null

I noticed that SOQL does not have field aliasing.

What is the best way around this?


I assume you are using the Force.com Toolkit for .NET for this?

In this case your Contact class should have a property of type Account that was also called Account. And the Account class would have the Account_Unique_ID__c property.

You could check this in the debugger with a dynamic type. Set a breakpoint in the loop and inspect the cont.

var dynamicContacts = await client.QueryAsync<dynamic>(query );
foreach (dynamic cont in dynamicContacts.Records)
    Console.WriteLine("Contact - " + cont.Account);

Another alternative would be to get the raw JSON response from the query. Something like Workbench or Fiddler could be useful here. Then create the C# classes for SFLocation and Account from that JSON using http://json2csharp.com/

  • Yes correct Force.com Toolkit for .NET. Adding a property of type Account to the Contact class worked a treat. Thanks! – David Nov 21 '15 at 10:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.