I am receiving the following error when running a test on my code. However, it seems to run fine in the debug line above it, so I'm confused regarding the source of the error:
System.QueryException: unexpected token: '<EOF>'
public static void careStatusChangeRelated(String careStatusChangeRelatedSerialized) {
// deserialize back into map
Map<String, Set<Id>> oppEntry= (Map<String, Set<Id>>)JSON.deserialize(careStatusChangeRelatedSerialized, Map<String, Set<Id>>.class);
List <CareProfileStatusChangeExit__mdt> allStatusCriteria = customMetadata;
//Set up a Query to pull the needed fields from Opportunity group
String query = 'SELECT ';
Set<String> queryfields = new Set<String>();
for(CareProfileStatusChangeExit__mdt field: allStatusCriteria){
//Add queryfields to update parent records
if(field.RelatedObject__c != null && field.RelatedObjectLookupFieldAPIName__c == null && field.APIFieldName__c != null){
queryfields.add(field.APIFieldName__c + ','); }
}
for(String statuskey: oppEntry.keySet()){
if(childRecordStatus.contains(statuskey)){
oppChanges.put(statuskey, oppEntry.get(statuskey));
}
}
If (queryfields.size()>0){
for(String q: queryfields){
query = query + q;}
List<Id> Vals = new List<Id>();
For(Set<Id>ids: oppEntry.values()){
for(Id is : ids){
Vals.add(is);
} }
//query = query.left(query.length() - 1);
query = query + ' Id FROM Opportunity WHERE Id IN: Vals';
System.debug('QUERY Vals' + Vals);
System.debug('QUERY:' + query);
System.debug('QUERY:' + (List<Opportunity>) Database.query(query));}
//Iterate over each Status to update related records based on metadata criteria
List<Opportunity> queryResults =(List<Opportunity>) Database.query(query);
query
string. – Adrian Larson♦ Feb 16 '18 at 16:57