0

I'm trying to export some data from my sandbox org for import into a scratch org, but I seem to be encountering an issue with my query:

enter image description here

MediaQualitySetJunction__c looks like this:

enter image description here

And this is the query I'm using:

SELECT
    Id,
    Name,
    (SELECT Id, Name, Width__c, Height__c, Resolution__c FROM MediaQuality__r)
FROM MediaQualitySetJunction__c

The full error:

Didn't understand relationship 'mediaquality__r' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.

I'm referencing MediaQuality by the its name on the junction object (with the __r suffix). I've also tried it without this suffix, and with the "Child Relationship Name" I see in Salesforce (MediaQualityJunction), with and without the __r, and I still get the same error.

Based on sfdcfox's answer, I've tried the following export:

sfdx force:data:tree:export -u "aaaaa@bbbbbbb.ccc" -q "SELECT Id, Name, MediaQuality__r.Id, MediaQuality__r.Name, MediaQuality__r.Width__c, MediaQuality__r.Height__c, MediaQuality__r.Resolution__c, MediaQualitySet__r.Id, MediaQualitySet__r.Name FROM MediaQualitySetJunction__c"

Which produces the following JSON:

{
    "records": [
        {
            "attributes":
            {
                "type": "MediaQualitySetJunction__c",
                "referenceId": "MediaQualitySetJunction__cRef1"
            },
            "Name": "000035",
            "MediaQuality__r":
            {
                "attributes":
                {
                    "type": "MediaQuality__c",
                    "url": "/services/data/v50.0/sobjects/MediaQuality__c/a020p000001WR5oAAG"
                },
                "Id": "a020p000001WR5oAAG",
                "Name": "1080p",
                "Width__c": 1920,
                "Height__c": 1080,
                "Resolution__c": "1920x1080"
            },
            "MediaQualitySet__r":
            {
                "attributes":
                {
                    "type": "MediaQualitySet__c",
                    "url": "/services/data/v50.0/sobjects/MediaQualitySet__c/a010p000001O3YZAA0"
                },
                "Id": "a010p000001O3YZAA0",
                "Name": "540p, 720p, 1080p (sandbox)"
            }
        }
    ]
}

And then executed the following to import it into my scratch org:

sfdx force:data:tree:import -u test-wvcnqftrp5tn@example.com -f "MediaQualitySetJunction__c.json"

I've confirmed that I have access to all of the fields involved and that the field visibility is checked for the System Administrator. I get the following result from the above command:

{
    "hasErrors": true,
    "results": [
        {
            "referenceId": "MediaQualitySetJunction__cRef1",
            "errors": [
                {
                    "statusCode": "INVALID_FIELD",
                    "message": "Cannot reference a foreign key field MediaQuality__r.",
                    "fields": []
                },
                {
                    "statusCode": "INVALID_FIELD",
                    "message": "Cannot reference a foreign key field MediaQualitySet__r.",
                    "fields": []
                }
            ]
        }
    ]
}

How do I solve this?

1

MediaQuality__c is the apparently parent of MediaQualitySetJunction__c, so you should be querying it as a parent relationship:

SELECT
    Id,
    Name,
    MediaQuality__r.Name, 
    MediaQuality__r.Width__c, 
    MediaQuality__r.Height__c, 
    MediaQuality__r.Resolution__c 
FROM MediaQualitySetJunction__c
4
  • Can I then import the resulting JSON into my scratch org? And is this documentation example wrong in that case? – Llama Dec 14 '20 at 9:45
  • I get the message "ERROR running force:data:tree:import: Cannot deserialize instance of <unknown> from VALUE_NUMBER_INT value 1920 or request may be missing a required field" when I try to import the JSON produced by this. I've confirmed that the fields all exist, etc. in my scratch org. – Llama Dec 14 '20 at 10:10
  • @John No, the documentation is correct. Broker__c is a parent of Property__c. You had your query backwards (as noted in my answer). In your scratch org, did you make sure all the field level security is set for your profile/permission set? Your JSON might be missing something, maybe you missed a field in your query? – sfdcfox Dec 14 '20 at 10:37
  • I've edited my question to include the JSON that is output, and the error I get when I try to import it. I'm also not sure how MediaQuality and MediaQualitySet can be the joint owners of MediaQualitySetJunction. – Llama Dec 15 '20 at 5:23

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.