4

I have a dev hub trial org where I have created an account record with the name 'Chaser' and it has an Id of '0011N00001Eam4C'

When I run the following command, I receive 'Query Returned No results'

sfdx force:data:tree:export -q "SELECT Name FROM Account WHERE Id = '0011N00001Eam4C'" -u DevHub -d ../sourceData

However, the strange thing is when I query by Name instead like so:

sfdx force:data:tree:export -q "SELECT Name FROM Account WHERE Name = 'Chaser'" -u DevHub -d ../sourceData

A Account.json file is populated with 1 record in the sourceData folder.

Why won't results come back when I query with the Id condition?

Thank you for your help!

Chase Klingel
  • 115
  • 1
  • 1
  • 7
  • If you add the ID to the SOQL query in the query that works, what does it come back with? If you aren't seeing 0011N00001Eam4CQAR then it would probably explain the issue. – Daniel Ballinger Feb 06 '18 at 19:24
  • @DanielBallinger it comes back with no records found. Is there a reason 'QAR' is appended to the Id and can you give me more explanation as to why this would explain the issue. Thank you for reaching out and trying to help. – Chase Klingel Feb 06 '18 at 20:33
  • There are both 15 and 18 character versions of Salesforce IDs. See What are Salesforce ID's composed of?. It might have explained a difference in casing on the ID. So what you are saying is that neither query comes back with any results now? – Daniel Ballinger Feb 06 '18 at 20:36
  • Just to clarify, I meant try this query: SELECT Id, Name FROM Account WHERE Name = 'Chaser' – Daniel Ballinger Feb 06 '18 at 20:37
  • To clarify, If I query where name = 'Chaser' I do get the expected 1 record returned. However if I query like so :

    SELECT Id, Name from Account where Id = '0011N00001Eam4C'

    I get the message no query results returned. If I go directly into the dev console in the environment I am exporting from, that query above where I specify the id does return 1 record as expected.

    – Chase Klingel Feb 06 '18 at 20:49
  • What is the ID that gets returned when SFDX does the query and uses the where name clause? I'm wondering if you need to use the full 18 character record ID for some reason in the export. In theory you shouldn't need to, but it is worth checking. – Daniel Ballinger Feb 06 '18 at 20:59
  • I tried with the 18. No luck. When I use the name as the where condition, the export works and then when I import the Id that was returned is: 001Z000001IoIDcIAN. I assume this id is going to obviously be randomly generated each time the record gets inserted into the target org in which I'm importing. – Chase Klingel Feb 06 '18 at 22:29
  • 1
    It's not the end of the world as we can query on other fields, but querying by Id should be acceptable criteria in my opinion. – Chase Klingel Feb 06 '18 at 22:30
  • I'm confused, are you saying the the ID is changing when you import the Account again? I'd fully expect that to happen as it is a new record with a new sequential ID specific to the target org. It's the same reason you don't hard code IDs in Apex as they can differ between orgs. – Daniel Ballinger Feb 06 '18 at 22:56
  • Yes it is and I would expect that as well. Earlier you were asking "What is the ID that gets returned when SFDX does the query and uses the where name clause?" there isn't an Id that gets returned. When the json file builds, it appears as follows

    { "records": [ { "attributes": { "type": "Account", "referenceId": "AccountRef1" }, "Name": "Chaser" } ] }

    Does this help at all?

    – Chase Klingel Feb 06 '18 at 23:51

0 Answers0