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
Nagarjuna Reddy.PNagarjuna Reddy.P 

System.QueryException : unexpected token

Hello Everyone,
  Here is my simple soql query
public static List<Account> updateMethod(id Id,List<String> selectedFields) {
   String squery = 'select Name,' +selectedFields+ 'FROM Account where id =:Id';
Account currentRec = database.query(squery);
}

Here selectedFields conatins accountfield API names which are passing from LWC js controller, I'm getting unexpected token issue

For Ex: selectedFields conatins Email__c,phone,name ect, I'm getting System.QueryException : unexpected token Email__c.

I'm not sure what might be the issue. Can any one help me.

Thank you.
ben stoke 1ben stoke 1
Out of 50 states, Texas has the highest number of people without  any health insurance like wecare riteaid com (https://infotainmentlab.com/wecare-riteaid-com/). So, what happens when they need health care? Who actually pays for emergency trips to the E.R.?
CharuDuttCharuDutt
Hii Nagarjuna 
Try Below Code
public static List<Account> updateMethod(id Id,String selectedFields) {
   String squery = 'select Name,' +selectedFields+ 'FROM Account where id =:Id';
list<Account> currentRec = database.query(squery);
        return currentRec;
}

Execute in Anonymous
YourClassName.updateMethod('Any Account Id put here','Phone,Accountnumber ');
Please Mark it As Best Answer If It Helps
Thank You!
Nagarjuna Reddy.PNagarjuna Reddy.P
Hello CharuDutt,

Thanks for your reply, Actually return statement exists , I tried again but still no luck facing the same issue.
CharuDuttCharuDutt
hii Nagarjuna
Paste The Below Line In place of  String Query
String squery = 'select Name,' +selectedFields+ ' FROM Account where id =:Id';
Please Mark It As Best Answer If It Helps
Thank You!