Skip to main content

I have an object called Assortment, it is the child of Account, and

the relationship is lookup. In graphql, the child relationship is named: Assortments. I try to get the Assortment from the account, 

but I got an error when I deploy LWC to my org: Invalid reference Account.Assortments__r of type sobjectField. The graphql is working on Altair. Anyone has an idea why?

The sample code: 

       Account (where: { Id: { eq: "001DT000015hjMpYAA" } } ) {

          edges {

            node {

              Id

              Name { value }

              Assortments__r {

                edges {

                  node {

                    Id

                    Name {value}

                  }

                }

              }

            }

          }

        } 

1 answer
  1. Aug 1, 2023, 7:40 AM

    Hi @Wenbo Liu,

     

    The graphql query you provided looks correct.

    But you can check the below points:

     

    Verify Relationship Name: Double-check that the child relationship name "Assortments__r" is correctly defined on the Account object. The relationship name should match the actual name of the child relationship on the Account object. Ensure there are no typos or misspellings in the relationship name.

     

    Check Field-Level Security: Make sure that the relationship field "Assortments__c" (or whatever the child relationship's API name is) is accessible and visible to the user running the GraphQL query. Ensure that the user has read access to both the Account object and the Assortment object.

     

    Field API Names: Ensure that the API names for fields like "Id" and "Name" are correct. The "Id" field is always available, but the "Name" field might have a different API name in your org, depending on any customizations or translations.

     

    Shield Platform Encryption: If your org uses Shield Platform Encryption, make sure that the fields involved in the query are not encrypted, as encrypted fields cannot be queried directly in GraphQL.

     

    Namespaces: If your org uses managed packages or has custom namespaces, verify that the field and relationship names are correctly qualified with the appropriate namespace prefix.

     

    Object Permissions: Confirm that the user executing the query has the necessary permissions to access both the Account and Assortment objects. If there are any sharing rules or record-level security settings, ensure that the user has access to the specific records involved in the query.

     

    Run the Query on a Salesforce Developer Console: Try running the query directly in the Salesforce Developer Console or Workbench to check if you encounter the same issue outside of your LWC component. This will help you identify if the issue is specific to the LWC or if it's a broader configuration problem.

     

    Best Regards

    Piyush