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
k209310k209310 

SOQL Relationships - Cant Query Related data

Hi there

Im trying to run a test SOQL relationships for thte first time and have encountered some problems.

I am running the query
SELECT a.Id, a.Name, (SELECT c.Id, c.firstname, c.lastname FROM a.Contacts c) FROM Account a
agsinst standard SalesForce objects however every time the query is executed against our account I am returned the error message
MALFORMED_QUERY: SOQL statements can't query related data

Has anyone got any ideas as to why this is occuring. As far as I can tell the syntax of the query is correct and I can run standard queries without any problem

Thanks

Chris
 

SuperfellSuperfell
You need to make sure you're using the 8.0 version of the API.
k209310k209310
Thanks for the reply

We are using API version 8.0

I.e We go to our account and download the latest version of the APEX API WSDL file from our account and build salesforce objects.

The header from the WSDL file is as follows...

<!--
Salesforce.com Enterprise Web Services API Version 8.0
Generated on 2007-01-22 04:37:19 +0000.

Copyright 1999-2007 salesforce.com, inc.
All Rights Reserved
-->

Thanks

Chris
SuperfellSuperfell
Can you post your code.
WhyserWhyser
I'm having a similar problem.
 
I have a custom object called Maintenance with some fields and it has a lookup field to the standard Product object, and has a Master Detail relationship with Account.
 
The query I am using is
 
Code:
Select Licenses__c, Maintenance_Price__c, Name, Total_Price__c, Maintenance_Status__c, Maintenance_Start_Date__c, Maintenance_End_Date__c, Product2__r.ProductCode 
from Maintenance__c where Account__c = '" + AccountIds[i] + "' Order By Name Desc

 where AccountIds[i] is for iterating this query with an array of Account Ids.
 
The error I am getting is
 
MALFORMED_QUERY: SOQL statements can't query related data
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.Services.Protocols.SoapException: MALFORMED_QUERY: SOQL statements can't query related data
 
The funny thing about this whole thing is that if I try to run this query using the Apex Explorer, it works just fine (as long as I substitute the AccountIds[i] for a valid Account Id).
Also, if I take out the "related data" part of the query, namely the Product2__r.ProductCode parameter from my query, the query works fine again.
 
I've even tried to change it up slightly, by replacing Product2__r.ProductCode with Account__r.Name. And I get the same error (though it still works in Apex Explorer).
 
Any ideas?
FYI I am using the API 13.0 Enterprise.wsdl


Message Edited by Whyser on 07-28-2008 09:46 AM

Message Edited by Whyser on 07-28-2008 02:30 PM
cpiyushcpiyush
Hey Whyser,

Did you get any solution for your problem?

I am also getting the same problem in executing relationship queries through my program(Python this time), even when the query is working fine with the Apex Explorer.

My detailed problem can be found here.

Looking for an urgent help.

Thanks,
Piyush.