The following SOQL in test classes gives a list of contacts but it doesn't lists any related account fields.
List<Contact> contacts = new List<Contact>([Select Id, Email, AccountId, Account.Name From Contact]);
If I use System.debug('contacts: ' + contacts);
- this just gives me the Id, Email and AccountId but no Account.name which is something like: (Contact:{[email protected], AccountId=00124000007HfzOAAS, Id=0032400000593u8AAA}, ...
Whereas, if I use - System.debug('contacts: ' + JSON.serialize(contacts));
- this gives me the related account name as well but in JSON format which is something like :
contacts: [{"attributes":{"type":"Contact","url":"/services/data/v33.0/sobjects/Contact/00324000004kGRqAAM"},"AccountId":"001240000076MPFAA2","Account":{"attributes":{"type":"Account","url":"/services/data/v33.0/sobjects/Account/001240000076MPFAA2"},"Name":"test","Id":"001240000076MPFAA2"},"Id":"00324000004kGRqAAM", "Email": "[email protected]"},....
Is there any other way to retrieve the related records in Apex Test Classes as the same SOQL seems to be working okay in normal apex class? Please let me know your thoughts.