
Set<String> fieldNames = schema.describeSObjects(new String[] {'User'})[0].fields.getMap().keyset();
List<String> iterableFields = new List<String>(fieldNames);
String query = 'SELECT '+ String.join(iterableFields,',')+ ' FROM User WHERE Id=:UserInfo.getUserId()';
User user = Database.query(query); //Line 10
When running the code, I am getting the below error:
- line 10, column 1
- System.QueryException: unexpected token: '('
Can somebody help what is the problem in this?
Hi deter dangler,Instead of using UserInfo.getUserId() directly in query string, take a ID variable and use that id value in query string. Here is the updated code try this.
Set<String> fieldNames = schema.describeSObjects(new String[] {'User'})[0].fields.getMap().keyset();
List<String> iterableFields = new List<String>(fieldNames);
Id usrId = UserInfo.getUserId();
String query = 'SELECT '+ String.join(iterableFields,',')+ ' FROM User WHERE Id=: usrId';
User user = Database.query(query); //Line 10
Best Regards,
Mithun.