I created strongly type classes to use when using the toolkit to query salesforce

public class SFAccount
    public string Id { get; set; }
    public string Name { get; set; }
    public string Account_Code__c { get; set; }

QueryResult<SFAccount> results = await _client.QueryAsync<SFAccount>(@"SELECT Id,
                                                                     FROM Account
                                                                     ORDER BY Id ASC");

This works fine as expected.

But when the query includes relationship columns using __r, I can't seem to get the toolkit to serialize my data to class object

public class SFLocation
    public string Id { get; set; }
    public string Name { get; set; }
    public string Account__c { get; set; }
    public string Account__r_Name { get; set; }
    public string Account__r_Account_Code__c { get; set; }           

QueryResult<SFLocation> results = await _client.QueryAsync<SFLocation>(@"SELECT Id,
                                                                FROM Location__c
                                                                ORDER BY Id ASC");

The last two properties (Account__r_Name and Account__r_Account_Code__c) are not being populated and my query is valid and returns data

How would I construct my class so that the toolkit would be able to serialize the result data to the class?

  • Did you ever get this resolved? I'm having the same issue – user3088377 Apr 27 '15 at 21:20
  • @user3088377 no,I just used QueryAsync<dynamic> for for queries that used relationship columns – iambdot Apr 28 '15 at 22:13
  • @user3088377 check out this reply from wade wagner, for the same question i asked him on his site disqus.com/home/discussion/developerrelations/… – iambdot Apr 29 '15 at 12:38

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

In this case your SFLocation class should have a property of type Account that it called Account__r. And the Account class would have the Name and Account_Code__c properties.

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

var dynamicLocations = await _client.QueryAsync<dynamic>(query );
foreach (dynamic sfl in dynamicLocations .Records)
    Console.WriteLine("location - " + sfl.Account__r);

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 Contact and Account from that JSON using http://json2csharp.com/

| improve this answer | |

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.