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
CmosCmos 

Malformed query: Unexpected Token Help

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

 

A problem with the OnClick JavaScript for this button or link was encountered:

{faultcode:'sf:MALFORMED_QUERY', faultstring:'MALFORMED_QUERY:
from Enrollment__c where Id IN (a0Fe000001LIGIEA4)
                               ^
ERROR at Row:1:Column:78
unexpected token: 'a0Fe000001LIGIEA4'', detail:{MalformedQueryFault:{exceptionCode:'MALFORMED_QUERY', exceptionMessage:'
from Enrollment__c where Id IN (a0Fe000001LIGIEA4)
                               ^
ERROR at Row:1:Column:78
unexpected token: 'a0Fe000001LIGIEA4'', row:'1', column:'78', }, }, }

 

The following is part of my code,

 

var PActivityQuery = "Select (Select Id From Program_Activities__r) From Enrollment__c WHERE Id = " + enrollObj.Id;
var PAqueryResult = sforce.connection.query(PActivityQuery);
var EnrollIt  = new sforce.QueryResultIterator(PAqueryResult);
while(EnrollIt.hasNext())
{
var tempPAEnroll = EnrollIt.next();
var newPActivity = [];
if(tempPAEnroll.Program_Activities__r)
{
var PAit = new sforce.QueryResultIterator(tempPAEnroll.Program_Activities__r);
while(PAit.hasNext())
{
var PActivityObj = PAit.next();

 Thanks

 

amarcuteamarcute

Hi,

 

As you are using a nested query & you have missed to specify the fields in the outer query, this exception is thrown. Replace 

 

var PActivityQuery = "Select (Select Id From Program_Activities__r) From Enrollment__c WHERE Id = " + enrollObj.Id;

with

var PActivityQuery = "Select Id, (Select Id From Program_Activities__r) From Enrollment__c WHERE Id = " + enrollObj.Id;

 

 

 

CmosCmos

Hey, thanks for the reply. I tired what you said but it still giving me the same exception. Anyother idea!?

 

Thanks

amarcuteamarcute

Hi,

 

Forgot to notice the usa of double quotes for the String. are you using single quotes insted of double quotes?

 

var PActivityQuery = 'Select Id, (Select Id From Program_Activities__r) From Enrollment__c WHERE Id = ' + enrollObj.Id;
CmosCmos

Hey, thanks for the help again. But I don't think single quotes or dobule quotes matters. I tried both and both of them still didn't work and giving the same exception. Got any other idea? 

 

Thanks

Satish_SFDCSatish_SFDC
Try enclosing the ID of the where clause in a single quote string:

eg:
..........where Id IN ('a0Fe000001LIGIEA4')

Regards,
Satish Kumar