1

Hey guys i am trying to get attachment Id in a subquery via the rest api in c# here is my query:

SELECT Id, Name, First_Name__c, Middle_Name__c, Last_Name__c, (SELECT Id FROM Attachments WHERE Name = 'ProfileImage.png' Limit 1) FROM Student_Bio__c

I execute the query this way:

var results = await client.QueryAsync<StudentBio>(qry);

The query runs fine but i am not getting my attachment data back in my StudentBio object. My student bio object looks like this (some fields removed to keep it small):

public class StudentBio
{
            /// <summary>
            /// The name of the Salesforce Object this class represents
            /// </summary>
            public const string SObjectTypeName = "Student_Bio__c";

            /// <summary>
            /// The API name of the Salesforce Object this class represents
            /// </summary>
            public const string ApiSObjectTypeName = "Student_Bio__c";

            public string Id { get; set; }
            public string Name { get; set; }
            public Attachments Attachments { get; set; }
    }

    public class Attachments
        {
            public RootObject[] Attachment { get; set; }
        }


        public class RootObject
        {
            public string Id { get; set; }
        }

when the query runs I get no errors but the value of StudentBio.Attachments is null when I expect to see one record

Here is an image of the object showing the null value

1 Answer 1

0

One option given in Querying Objects with the new Force.com Toolkit for .NET is to use the QueryResult type to get the result back. You would then get the subquery results via the records property.

Maybe run the SOQL query in workbench to get the raw SOQL response. They run it though http://json2csharp.com to generate the POCO objects.

1
  • thanks, I ended up getting it to work by generating the objects. It was the requirement of needing a class called 'RootObject' that was causing me issues. And that it need to be the type assigned to the property 'Attachments' and the type 'RootObject' needed a property called 'records' of type List<Attachment>
    – Andrew Day
    Mar 10, 2016 at 16:26

You must log in to answer this question.

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