We have a custom button Javascript which queries child records, validates them and then alert the User with a message. Though I am correctly querying the child records I get an error :faultcode:'sf'INVALID_FIELD'. I am an admin and have all permissions. Below is the query:

    Select childrec__r.cusfield__c from customobj__c where id ='{!customobj__c.Id}'

1 Answer 1


If you are querying customobj__c and its child relationship childrecs__r, the correct syntax is:

SELECT Id, <any other parent record fields>,
    (SELECT Id, <any other child record fields>, cusfield__c FROM childrecs__r)
FROM customobj__c WHERE Id = '<parent id goes here>'

The convention is usually that the child relationship has a plural name. If you're not sure what it was set to, double-check by going to the child object in Setup and viewing the lookup field to customobj__c to see what was set as the child relationship API name (not the field API name) for that lookup.

Or if you need only the children:

SELECT Id, <any other child record fields>, cusfield__c
FROM <child object name>__c 
WHERE <parent relationship name>__c = '<parent id goes here>'

You must log in to answer this question.

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