You need to sign in to do that
Don't have an account?
Nick Stebner
System.QueryException: unexpected token:
Hello, and thanks in advance for any responses!
I am trying to return a list of records from another custom object (Values_dreams_Goals) for display on my current custom object (VDG_Display). The code below has been adapted from another application in the same org that works just fine, but returns the query error below.
System.QueryException: unexpected token: SELECTValues_Dreams_Goals__c
Class.GoalListExt.getGoalItems: line 25, column 1
My offending class is below. Line 25 is marked, but I may have an error in the query language itself, since I'm somewhat unfamiliar with it.
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public class GoalListExt {
public id householdId {get;set;}
public VDG_Display__c thisDisplay {get;set;}
public list<Values_Dreams_Goals__c> GoalItems;
public integer QUERY_RECORD_LIMIT = 25;
public GoalListExt() {
}
public list<Values_Dreams_Goals__c> getGoalItems()
{
string parentID = householdId;
string query = 'SELECT';
for(Schema.FieldSetMember f : this.getGoalItemsFields())
{
query += f.getFieldPath() + ',' ;
}
query += 'Id FROM Values_Dreams_Goals__c WHERE Household_linked__c =: parentID limit:QUERY_RECORD_LIMIT';
line 25 --> GoalItems = (list<Values_Dreams_Goals__c>) Database.query(query);
return GoalItems;
}
public List<Schema.FieldSetMember> getGoalItemsFields() {
return SObjectType.Values_Dreams_Goals__c.FieldSets.VDGTable.getFields();
}
}
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Any help would be appreciated.
Thanks in advance.
Nick
I am trying to return a list of records from another custom object (Values_dreams_Goals) for display on my current custom object (VDG_Display). The code below has been adapted from another application in the same org that works just fine, but returns the query error below.
System.QueryException: unexpected token: SELECTValues_Dreams_Goals__c
Class.GoalListExt.getGoalItems: line 25, column 1
My offending class is below. Line 25 is marked, but I may have an error in the query language itself, since I'm somewhat unfamiliar with it.
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public class GoalListExt {
public id householdId {get;set;}
public VDG_Display__c thisDisplay {get;set;}
public list<Values_Dreams_Goals__c> GoalItems;
public integer QUERY_RECORD_LIMIT = 25;
public GoalListExt() {
}
public list<Values_Dreams_Goals__c> getGoalItems()
{
string parentID = householdId;
string query = 'SELECT';
for(Schema.FieldSetMember f : this.getGoalItemsFields())
{
query += f.getFieldPath() + ',' ;
}
query += 'Id FROM Values_Dreams_Goals__c WHERE Household_linked__c =: parentID limit:QUERY_RECORD_LIMIT';
line 25 --> GoalItems = (list<Values_Dreams_Goals__c>) Database.query(query);
return GoalItems;
}
public List<Schema.FieldSetMember> getGoalItemsFields() {
return SObjectType.Values_Dreams_Goals__c.FieldSets.VDGTable.getFields();
}
}
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Any help would be appreciated.
Thanks in advance.
Nick
About line 25: You don't need to downcast Database.query(query) to a List<Values_Dreams_Goals__c> because Values_Dreams_Goals__c is in your FROM clause; this is redundant.
Also, check out SoqlBuilder from apex-lang: http://apex-commons.github.io/query/soql-builder/ using this library can remove silly syntax errors like this, since you'll no longer need to worry about them.
Check out the following example method your query in the above code could become in some other class (let's say, "ValuesDreamsGoalsService.cls" if you were using SoqlBuilder:
Then in your code, you would simply write:
Thanks so much. That worked perfectly.
Nick