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
Nishant Prajapati 10Nishant Prajapati 10 

Trailhead Superbatch Process Automation - Step 6 Error

There was an unhandled exception. Please reference ID: HTNVCCJL. 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: 4

My Flow looks like: 
User-added image
User-added image
User-added image
User-added image
User-added image
Best Answer chosen by Nishant Prajapati 10
NagendraNagendra (Salesforce Developers) 
Hi Nishant,

Please check with below information

Summary: Salesforce has put a restriction for queries containing Fullname or Metadata field and it is for all objects. It is because we have performance concerns on the query system if the query result involves multi records of entities including Fullname/Metadata fields. 

Note this restriction doesn't apply to queries that are not selecting Fullname/Metadata fields.

Repro:
1.) Login to an ORG using WorkBench 
2.) Go to the Rest explorer and execute the following GET on any entity which has more than one row, in our case Layout -- 

/services/data/v33.0/tooling/query/?q=SELECT+Id%2C+Name%2C+FullName%2C+TableEnumOrId%2C+Metadata+FROM+Layout 

and you would see an error 

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: [n>1] 

Whereas if you remove the Fullname and Metadata fields from the query, you would get the expected results.
Workaround
Query this field only if the query result contains no more than one record. Otherwise, an error is returned. 
If more than one record exists, use multiple queries to retrieve the records. This limit protects performance. 

// Get all the IDs 
SELECT Id FROM Layout WHERE TableEnumOrId IN (Contact, Opportunity, Quote) ORDER BY Name 

// Do this for each id 
SELECT FullName, Metadata, Name, TableEnumOrId FROM Layout WHERE id = 'Some_id' 

Hope this helps.

Mark this as solved if the information helps.

Thanks,
Nagendra

All Answers

NagendraNagendra (Salesforce Developers) 
Hi Nishant,

Please check with below information

Summary: Salesforce has put a restriction for queries containing Fullname or Metadata field and it is for all objects. It is because we have performance concerns on the query system if the query result involves multi records of entities including Fullname/Metadata fields. 

Note this restriction doesn't apply to queries that are not selecting Fullname/Metadata fields.

Repro:
1.) Login to an ORG using WorkBench 
2.) Go to the Rest explorer and execute the following GET on any entity which has more than one row, in our case Layout -- 

/services/data/v33.0/tooling/query/?q=SELECT+Id%2C+Name%2C+FullName%2C+TableEnumOrId%2C+Metadata+FROM+Layout 

and you would see an error 

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: [n>1] 

Whereas if you remove the Fullname and Metadata fields from the query, you would get the expected results.
Workaround
Query this field only if the query result contains no more than one record. Otherwise, an error is returned. 
If more than one record exists, use multiple queries to retrieve the records. This limit protects performance. 

// Get all the IDs 
SELECT Id FROM Layout WHERE TableEnumOrId IN (Contact, Opportunity, Quote) ORDER BY Name 

// Do this for each id 
SELECT FullName, Metadata, Name, TableEnumOrId FROM Layout WHERE id = 'Some_id' 

Hope this helps.

Mark this as solved if the information helps.

Thanks,
Nagendra
This was selected as the best answer
Nishant Prajapati 10Nishant Prajapati 10
Thanks Nagendra.
This worked for me. Actually I had 4 Lightning Record Pages on Opportunity object. I just keep the default and deleted rest. 
NagendraNagendra (Salesforce Developers) 
Hi Nishant,

I am glad it helped.

May I request you please close this thread by marking it as solved so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue.

Thanks,
Nagendra.