0

I am trying to fetch contact names from case object using apex class but instead of contact name its giving me contactId. Please help me to fetch Contact Name.

Expected Output: DEBUG|(Case:{Name=SomeName, CaseNumber=00001032, Status=New, Id=5005g000009pWu5AAE}

Actual Output: DEBUG|(Case:{ContactId=0035g000009ofFFAAY, CaseNumber=00001032, Status=New, Id=5005g000009pWu5AAE}

Here is my apex class code:

public with sharing class Report {
    public Report() {

    }

    @AuraEnabled
    public static List<Case> fetchRecords(){
        List<Case> caseList = new List<Case>();
        try {
            caseList = [SELECT Contact.Name, CaseNumber, Status  FROM Case];
            System.debug(caseList);
            return caseList;
        } catch (Exception e) {
            throw new AuraHandledException(e.getMessage());
        }
    }
}


2

System.debug(sObject) does not show parent or child relationships, only direct fields. The value is being queried, and is available in memory, but will not be output in a System.debug statement unless you somehow serialize the record:

System.debug(JSON.serializePretty(caseList));
2
  • Thanks a lot @sfdcfox. Didn't knew that System.debug does not show parent or child relationships. Just learnt something new from you. :) Jul 22 at 9:27
  • @user9824674 You're welcome!
    – sfdcfox
    Jul 22 at 9:32

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.