I'm using Visualforce Remoting to get information about a Contact. I want to get a specific Attachment related to the Contact at the same time (which is linked through ParentId).

When I return the Contact, the result does not seem to include information about the child objects.

My Contacts.page



    function(result, event){




    global static Contact getContact(Id contactId){

        Contact selContact = [SELECT Id, (Select Id from Attachments where ParentId = :contactId and Name = 'Contact Picture'), Name, FirstName, LastName  FROM Contact WHERE Id=:contactId limit 1];
        return selContact;

console.log returns:

result: Object

FirstName: "John" Id: "003U000000s2RmEIAU" LastName: "Smith" Name: "John Smith"

and there is no Attachments array. I know I could do it with another RemoteAction, or by using a Wrapper Class, but I thought this would work.

  • The query returns the attachment results when you execute it through and IDE/dev console/workbench right ? Sep 24, 2014 at 17:44
  • Can you verify that there are child attachments for the specific Contact you requested?
    – Adrian Larson
    Sep 24, 2014 at 17:44
  • 1
    Gah. I queried the wrong Contact. With the right one the Attachments array is indeed specified. Should I delete my question?
    – George S.
    Sep 24, 2014 at 17:49
  • @GeorgeS. I would rather post the comment as answer and mark it solved. Would help others who stop by later
    – Rao
    Sep 24, 2014 at 17:51
  • Answer it yourself, then accept your answer. Then you can get the booty and your goof is searchable for eternity :D Sep 24, 2014 at 17:52

1 Answer 1


I had queried with the wrong Contact ID, with a Contact who did not have Attachments. This naturally does not return a blank Attachments array, but rather no array at all.

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.