Why my soql query is returning 'RecordTypeId' instead of the fields mentioned in the query?

Here's my query:

SELECT Id, Name, ABC, (SELECT Id, XYZ FROM InnerObject) FROM OuterObj

Note: My query contains a subquery.

  • 4
    Please post your query. – Martin Lezer Jul 21 '17 at 12:50
  • SELECT Id, Name, ABC, (SELECT Id, XYZ FROM InnerObject) FROM OuterObj – Surya Jul 21 '17 at 12:53
  • What do you mean by returning 'RecordTypeId'? – Martin Lezer Jul 21 '17 at 12:54
  • When I run the same query in developer console I am getting the result as expected, but when I run the query in apex class using Database.query() method I am getting the Id field Name field and a RecordTypeId. – Surya Jul 21 '17 at 12:55
  • Please post your whole code. It's really difficult to help without it and with a pseudo code query. – Martin Lezer Jul 21 '17 at 12:56

If you're using System.debug, this is expected. SObject's default "toString" method doesn't show subqueries. If you're interested in seeing that data, you need to debug the subquery instead:

OuterObj[] outerObjList = [SELECT Name, (SELECT XYZ FROM InnerObject) FROM OuterObj];
for(OuterObj record: outerObjList) {

RecordTypeId is a field automatically appended to your query by the SOQL engine in Apex Code. This is done so that Visualforce can automatically determine which picklist values are available for a given picklist field.


Not the answer you're looking for? Browse other questions tagged or ask your own question.