4

Good Morning, Thanks in advance for reading.

Is there any way to display the whole sObject in the resultset returned by SOQL query instead of the (n more) below e.g. 30 more, 22 more etc. ? I am trying to display simple information - in this case, all usernames and emails of Hiring Managers in a particular department.

This is the Recruiting app schema in the Apex Training org.

"s": 1,
"v": {
    "Name": "APP-0000",
    "Position__c": "a0561000000eWXAAA2",
    "Id": "a0261000001QKWSAA4",
    "Position__r": {
        "s": 2,
        "v": {
            "Id": "a0561000000eWXAAA2",
            "Hiring_Manager__c": "00561000000vrVtAAI",
            "Type__c": "Full Time",
            "Status__c": "New",
            "Hiring_Manager__r": {
                "s": 3,
                "v": {
                    "Id": "00561000000vrVtAAI",
                    "Username": "ben_stuart.ridoajnog (30 more) ...",
                    "Email": "ben_stuart_sfdc_uc=e (22 more) ...",
                    "UserType": "Standard"
                }
            }
        }
    }
}

Here is the output from my debug log:

|DEBUG|This is the application name: APP-0000
|DEBUG|This is the Position: Position__c:{Id=a0561000000eWXAAA2, Hiring_Manager__c=00561000000vrVtAAI, Type__c=Full Time, Status__c=New}
|DEBUG|This is the Hiring Manager : User:{Id=00561000000vrVtAAI, [email protected], [email protected], UserType=Standard}
|DEBUG|This is the application name: APP-0006
|DEBUG|This is the Position: Position__c:{Id=a0561000000eWX1AAM, Hiring_Manager__c=00561000000vrVwAAI, Type__c=Full Time, Status__c=Closed}
|DEBUG|This is the Hiring Manager : User:{Id=00561000000vrVwAAI, [email protected], [email protected], UserType=Standard}
|DEBUG|This is the application name: APP-0013
|DEBUG|This is the Position: Position__c:{Id=a0561000000eWWvAAM, Hiring_Manager__c=00561000000vrVuAAI, Type__c=Full Time, Status__c=Open}
|DEBUG|This is the Hiring Manager : User:{Id=00561000000vrVuAAI, [email protected], [email protected], UserType=Standard}

I have the following anonymous exec block :

    List<Job_Application__c> jobAppls = [select Name, 
                                 Position__r.Hiring_Manager__c,  
                                 Position__r.Hiring_Manager__r.UserName, 
                                 Position__r.Hiring_Manager__r.Email, 
                                 Position__r.Hiring_Manager__r.UserType, 
                                 Position__r.Type__c, Position__r.Status__c 
                                 from Job_Application__c 
                                 where Position__r.Department__c = 'Engineering' 
                                 order by Name ASC];

    for (Job_Application__c appl : jobAppls){
     System.debug('This is the application name: '+appl.Name);
     System.debug('This is the Position: '+appl.Position__r); 
     System.debug('This is the Hiring Manager : '+appl.Position__r.Hiring_Manager__r);                 
    }

I am able to get the information I need, just wondering if there was a mechanism to see the whole JSON tree in the log output.

If this is an already answered question, just a link will do as well! I am brand new to the SFCOM platform, there is so much to learn! Thanks greatly.

Regards, VeeCan

1 Answer 1

5

Yes, there is a way, however please note that this will turn out to be costly in terms of processing/CPU time so avoid this in your production code and while performance testing.

 List<Job_Application__c> jobAppls = [select Name, 
                                 Position__r.Hiring_Manager__c,  
                                 Position__r.Hiring_Manager__r.UserName, 
                                 Position__r.Hiring_Manager__r.Email, 
                                 Position__r.Hiring_Manager__r.UserType, 
                                 Position__r.Type__c, Position__r.Status__c 
                                 from Job_Application__c 
                                 where Position__r.Department__c = 'Engineering' 
                                 order by Name ASC];

System.debug(JSON.serialize(jobAppls)); //JSON is a standard Salesforce Class

JSON Class

Also there are some limitations on what types can be serialized but in your case since it's an sObject, I believe it will work just fine.


Update: 20 May 2016

You can also use serializePretty to view formatted debug

System.debug(JSON.serializePretty(jobAppls)); //JSON is a standard Salesforce Class

0

You must log in to answer this question.

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