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
AnnaTAnnaT 

MALFORMED_QUERY: unexpected token: ':'

The following error occurrs but I don't know how to solve this.

 

MALFORMED_QUERY: childObj__r where Location__c = :tmpVar1) from ParentObj__c ^ ERROR at Row:1:Column:227 unexpected token: ':'

[Select r.Name,r.Id,
         (Select Status__c 
           From childObj__r 
          WHERE Location__c=:location )  
   From ParentObj__c r 
  where r.Location__c includes (:location) order by r.Name]));

 Thanks in advance for your help!

Anna

 

Best Answer chosen by Admin (Salesforce Developers) 
AnnaTAnnaT

It seems that ":" can't be used in the nested query.

The following code works!

'Select r.Name,r.Id,'+
         '(Select Status__c '+
         '  From childObj__r '+
         ' WHERE Location__c=\'' +location + '\' ' +
  ')From ParentObj__c r '+
  'where r.Location__c includes (:location) order by r.Name'));

 

Thank you,

Anna 

All Answers

ForcepowerForcepower
Anna - can you try removing the parens around :location?
where r.Location__c includes :location order by r.Name]
ForcepowerForcepower
Never mind - that's not it.
AnnaTAnnaT

Thank you for your reply.

Yes, this issue seems to occurr at the first ":location".

Without the following bold line, no error occurrs.

[Select r.Name,r.Id,
         (Select Status__c 
           From childObj__r 
          WHERE Location__c=:location )  
   From ParentObj__c r 
  where r.Location__c includes (:location) order by r.Name]));
Bhawani SharmaBhawani Sharma
what is the data type of location variable?
ForcepowerForcepower
So is Location__c a field on parent and also on child? I'm assuming it's a multi picklist on the parent.
AnnaTAnnaT
The data type of location variable is string.

These two Location__c is different.
Location__c of child object is Picklist.
Location__c of parent object is Picklist (Multi-Select) .

Thank you,
Anna
AnnaTAnnaT

It seems that ":" can't be used in the nested query.

The following code works!

'Select r.Name,r.Id,'+
         '(Select Status__c '+
         '  From childObj__r '+
         ' WHERE Location__c=\'' +location + '\' ' +
  ')From ParentObj__c r '+
  'where r.Location__c includes (:location) order by r.Name'));

 

Thank you,

Anna 

This was selected as the best answer
ForcepowerForcepower
Anna,

Good to know. Interesting idiosyncrasy of SOQL. Not sure if they cannot parse a : within a nested query or what. Thanks for sharing the solution!
Ram
THBrunoTHBruno

Isn't that giving an error upon execution of the query?