function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Pramod VPramod V 

Lightning component trailhead

Hi All,

I am new to SF. I have been completing quite a few challenges now, I am stuck in this one for long.

https://trailhead.salesforce.com/projects/quickstart-lightning-components/steps/quickstart-lightning-components3

Quite frustrating actually.

Everytime I get this error:
There was an unhandled exception. Please reference ID: BCGRRLJQ. Error: Faraday::ClientError. Message: MALFORMED_QUERY: When retrieving results with Metadata or FullName fields, the query qualificatio​ns must specify no more than one row for retrieval. Result size: 3

I looked at other similar post, but not helpful.

I tried adding limit in Controller and checked the query in SOQL editor also. The result returned is always 1. I tried in multiple trailhead Playgrounds still the same.

Not sure where I am going wrong. Any suggestions will help.

Thanks,
Pramod V
Raj VakatiRaj Vakati
refer thhis link for code 
https://github.com/TaaaZyyy/lightning-playground/tree/master/force-app/main/default/aura/MyContactList
Raj VakatiRaj Vakati
public with sharing class MyContactListController {
    @AuraEnabled
    public static List<Contact> getContacts(Id recordId) {
        return [
            SELECT
                Id,
                FirstName,
                LastName,
                Email,
                Phone
            FROM
                Contact
            WHERE
                AccountId = :recordId
        ];
    }
}
 
<aura:component controller="MyContactListController" implements="flexipage:availableForRecordHome,force:hasRecordId" access="global" >
    <aura:attribute name="recordId" type="Id"/>
    <aura:attribute name="Account" type="Account"/>
    <aura:attribute name="Contacts" type="Contact"/>
    <aura:attribute name="Columns" type="List"/>

    <aura:handler name="init" value="{!this}" action="{!c.myAction}"/>

    <force:recordData aura:id="accountRecord" recordId="{!v.recordId}" targetFields="{!v.Account}" layoutType="FULL"/>
    <lightning:card iconName="standard:contact" title="{!'Contact List for ' + v.Account.Name}">
        <lightning:datatable data="{!v.Contacts}" columns="{!v.Columns}" hideCheckboxColumn="true"/>
    </lightning:card>
</aura:component>
 
({
    myAction : function(component, event, helper) {
        component.set("v.Columns", [
            {label:"First Name", fieldName:"FirstName", text:"text"},
            {label:"Last Name", fieldName:"LastName", type:"text"},
            {label:"Phone", fieldName:"Phone", type:"phone"}
        ]);
        let action = component.get("c.getContacts");
        action.setParams({
            recordId: component.get("v.recordId")
        });
        action.setCallback(this, function(data) {
            component.set("v.Contacts", data.getReturnValue());
        });
        $A.enqueueAction(action);
    }
})

 
Mario PariseMario Parise
Hi Pramod,

If the source code Raj shared doesn't fix your issue (I believe it should), can you share your code with us?

Thanks!
Pramod VPramod V
Thank you for your responses,

After employing Raj's code I get following error:

The component does not contain the correct lightning:card markup.

I somehow feel this is not an issue with code. Have to do with admin stuff. 

Skeptical that one of the previous challenges affecting this, but not sure how to validate.

Thanks,
Pramod V
Mario PariseMario Parise
The error, "component does not contain the correct markup", suggests it is an issue with the code. Can you share your component code?
Pramod VPramod V
<aura:component controller="MyContactListController" implements="flexipage:availableForRecordHome,force:hasRecordId" access="global" >
    <aura:attribute name="recordId" type="Id"/>
    <aura:attribute name="Account" type="Account"/>
    <aura:attribute name="Contacts" type="Contact"/>
    <aura:attribute name="Columns" type="List"/>

    <aura:handler name="init" value="{!this}" action="{!c.myAction}"/>

    <force:recordData aura:id="accountRecord" recordId="{!v.recordId}" targetFields="{!v.Account}" layoutType="FULL"/>
    <lightning:card iconName="standard:contact" title="{!'Contact List for ' + v.Account.Name}">
        <lightning:datatable data="{!v.Contacts}" columns="{!v.Columns}" hideCheckboxColumn="true"/>
    </lightning:card>
</aura:component>
 
({
    myAction : function(component, event, helper) {
        component.set("v.Columns", [
            {label:"First Name", fieldName:"FirstName", text:"text"},
            {label:"Last Name", fieldName:"LastName", type:"text"},
            {label:"Phone", fieldName:"Phone", type:"phone"}
        ]);
        let action = component.get("c.getContacts");
        action.setParams({
            recordId: component.get("v.recordId")
        });
        action.setCallback(this, function(data) {
            component.set("v.Contacts", data.getReturnValue());
        });
        $A.enqueueAction(action);
    }
})
 
public with sharing class MyContactListController {
    @AuraEnabled
    public static List<Contact> getContacts(Id recordId) {
        return [
            SELECT
                Id,
                FirstName,
                LastName,
                Email,
                Phone
            FROM
                Contact
            WHERE
                AccountId = :recordId
        ];
    }
}

 
Mario PariseMario Parise
Hi Pramod,

I tested the component, copying and pasting your exact code. I did not get the same error as you, however you have an error in this element:
<lightning:datatable data="{!v.Contacts}" columns="{!v.Columns}" hideCheckboxColumn="true"/>
It requires the keyField attribute:
<lightning:datatable data="{!v.Contacts}" columns="{!v.Columns}" keyField="Id" hideCheckboxColumn="true"/>
With that change only, your exact code works in my development org. Hopefully that's your only error! :-)
Pramod V 3Pramod V 3
I did the change you mentioned, but it is still the same.
Mario PariseMario Parise
You're still getting the "The component does not contain the correct lightning:card markup." error?

I truly am baffled. I literally copy and pasted your own code and succeeded, other than adding keyField. I even re-earned my trailhead badge for it.

My only recommendation would be to create a new developer org just for these purposes (maybe something got messed up in the one you're testing in), and creating the class and components from fresh.
Pramod VPramod V
Hmm, Strange!

Let me create a new TP and test this.

~VIP
Pramod VPramod V
Okay, I tried following:
  • Create a new TP and did the same - didn't work
  • Re-did/recheck all the development side of things(to the best of my knowledge) - didn't work
  • Checked at SOQL editor if my query runs or not. It runs fine.
I either get Record size limit error or my Lighting app wont load in App builder.

~VIP
James187 LittlejohnJames187 Littlejohn
Were you able to solve the error? I am facing the same problem. 

https://mybkexperience.us/
Pramod VPramod V
Yes, I was able to. I deleted all the Account Record Page layouts, lightning components in the same TP and re-did everything. It worked for me after these changes.