4

I am using .NET toolkit for integration with salesforce.com One of the queries I have is

Select Id, Name, ConvertedOpportunityId, ConvertedOpportunity.Amount , ConvertedOpportunity.Name, ConvertedOpportunity.ExpectedRevenue FROM Lead WHERE LastModifiedDate > LAST_MONTH AND IsConverted = true;

This query works in the workbench as is, but when I bring it over for use with the .NET toolkit, it fails to give me the ExpectedRevenue field value. The value returned is a NULL. I understand that I cannot use a field alias in my code so what is an alternative?

Here is a snippet of code from .NET

    var leads = await client.QueryAsync<Lead>("Select Id, Name, ConvertedOpportunityId, ConvertedOpportunity.Amount , ConvertedOpportunity.Name, ConvertedOpportunity.ExpectedRevenue FROM Lead WHERE LastModifiedDate > LAST_MONTH AND IsConverted = true");
        foreach(var lead in leads.Records)
        {
            Console.WriteLine("Id:{0}\t Name:{1}\t \t Opp: {2}\t Rev: {3} ", lead.Id, lead.Name, lead.ConvertedOpportunityId,lead.ExpectedRevenue);
        }


    private class Lead
    {
        public const String SObjectTypeName = "Lead";
        public string Id { get; set; }
        public string Name { get; set; }
        public bool IsConverted { get; set; }
        public string ConvertedOpportunityId { get; set; }
        public decimal? ExpectedRevenue { get; set; }
    }

1 Answer 1

4

You will also need an Opportunity class with the fields that you have queried from ConvertedOpportunity.

Something like (untested):

private class Lead
{
    public const String SObjectTypeName = "Lead";
    public string Id { get; set; }
    public string Name { get; set; }
    public bool IsConverted { get; set; }
    public Opportunity ConvertedOpportunity { get; set; }

}

private class Opportunity
{
    public const String SObjectTypeName = "Opportunity";
    public decimal? Amount { get; set; }
    public string Name { get; set; }
    public decimal? ExpectedRevenue { get; set; }

}
3
  • Hi Daniel, Thanks for the reply. This is exactly what I have done. One small change - inside the Opp class, I needed to define the SObjectTypeName.
    – abhi
    May 18, 2016 at 21:50
  • @abhi Like that? May 18, 2016 at 21:53
  • Yes. That is what I had to do.
    – abhi
    May 18, 2016 at 22:00

You must log in to answer this question.

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