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
BhawnaBhawna 

MALFORMED_QUERY: SOQL statements can't query related data

Hi, 

 

I'm facing the error message 'MALFORMED_QUERY: SOQL statements can't query related data'

 

thrown by this query

 

"SELECT Id, Name, (SELECT Quantity, ListPrice, PricebookEntry.UnitPrice, PricebookEntry.Name FROM OpportunityLineItems) FROM Opportunity o where o.Id='"+{!Opportunity.Id}+"'";

 

Since this gives the result on the Eclipse, force.com.

Any guidenance will be appreciated..

 

 

thanks,

SteveBowerSteveBower

OpportunityLineItem does not have a Child Relationship with PricebookEntries.  It merely has an Pricebook Entry Id.

 

I suggest using the Eclipse schema viewer / query tool to help you build complex queries.  

 

Best, Steve.

 


 

BhawnaBhawna

Hi Steve,

 

I tried to form different queries on OpportunityLineItem using Eclipse, they all run properly with such relationship.

like :

 

"Select o.Id,o.Description, o.Discount__c, o.OpportunityId,o.TotalPrice, o.PricebookEntryId,o.PricebookEntry.Product2Id, o.PricebookEntry.UnitPrice, o.Quantity from OpportunityLineItem o where o.OpportunityId='"+{!Opportunity.Id}+"'"

 

but when I use this query in js like:

 

var queryOppline=sforce.connection.query("Select o.Id,o.Description, o.Discount__c, o.OpportunityId,o.TotalPrice,   o.PricebookEntryId,o.PricebookEntry.Product2Id, o.PricebookEntry.UnitPrice, o.Quantity from OpportunityLineItem o where o.OpportunityId="+"'"+"{!Opportunity.Id}"+"'");

var Records=queryOppline.getArray('records');

 

It throws an error.

 

I searched in the forum also, we use such relatioship.

 

Similar ex. is given in the "sforce_API.pdf"

kindly, get me out from this situation.

 

 

with lot of thanks,

SteveBowerSteveBower

This query is different from the previous one... this one is valid and the select below runs fine for me:

 

Select o.UnitPrice, o.TotalPrice, o.Quantity, o.PricebookEntry.Product2Id, o.PricebookEntryId, o.OpportunityId, o.Id, o.Description From OpportunityLineItem o where o.OpportunityId='00630000002zTEJAA2'

 

 

Perhaps you're not building your strings correctly, it's difficult to tell.

 

You could write:

 

var q = "Select ..... from OpportunityLineItem o where o.OpportunityId='{!Opportunity.Id}' ";

alert(q);  // If you want to see it.

var queryOppLine = sforce.connection.query(q);

 

 

You should also use the FireBug extension for s-control development.

 

Best, Steve (going to bed...)

 

SuperfellSuperfell
You're using an API version that was released prior to the addition of SOQL-R (so earlier than 8.0), change your api client to use a newer api version.
BhawnaBhawna

Hi Simon,

 

 I'm using the latest version of API i.e 15, I cross checked my code on below this version till 13 and faced the same error message. 

 

 

 

Bhawna

 

SuperfellSuperfell
Seems unlikely, can you post a capture of your HTTP request that returns the error ?
BhawnaBhawna

Hi,

 

I have done it, by resolving the query into parts, means related list query is executed based on the Id of related field fetched in the main query.

 

Thanks a lot for sparing time.  :smileyhappy: