3

I'm running the following query which contains a child => parent relationship between Case and Account - and contains the Account.Name in the SELECT:

string query = "SELECT Case.CaseNumber,Case.Account.Name,Case.Status FROM Case WHERE Status != 'Closed' AND OwnerId IN (SELECT Id FROM User WHERE Email = '" + userEmail + "') ORDER BY Account.Name";
var results = await client.QueryAsync<CaseWorkload>(query);

The CaseWorkload class is defined as:

public class CaseWorkload
{
    public string CaseNumber { get; set; }
    public string Status { get; set; }
    public string AccountName { get; set; }
}

I am unable to retrieve the AccountName information as the returned SQL shows Account.Name and I couldn't find a way in SOQL to alias a column. How should the class be created considering the given query?

Dale K
  • 16,372
  • 12
  • 37
  • 62

1 Answers1

5

You need to do the following to get the Account Name - then of course you can map the Account Name to a property in CaseWorkload if desired:

public class CaseAccount
{
    public string Name { get; set; }
}

public class CaseWorkload
{
    public string CaseNumber { get; set; }
    public string Status { get; set; }
    public CaseAccount Account { get; set; }
}
Dale K
  • 16,372
  • 12
  • 37
  • 62
  • what about if you have a waterfall relationship? Example: public class CaseAccount { public string Name { get; set; } public User Owner { get; set; } public User CreatedBy { get; set; } } public class CaseWorkload { public string CaseNumber { get; set; } public string Status { get; set; } public CaseAccount Account { get; set; } } The User objects are never filled from the return of this query. I am adding CreatedBy.Name, CreatedBy.Phone, Owner.Name, Owner.Phone in the query. Using Postman I see the result of the query is working fine. – CidaoPapito Nov 15 '17 at 15:34