You need to sign in to do that
Don't have an account?
deter dangler
Database.query() method throwing syntax error
I have the below code:
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 10When running the code, I am getting the below error:
- line 10, column 1
- System.QueryException: unexpected token: '('
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. Best Regards,
Mithun.
All Answers
Just learnt from this link http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_dynamic_soql.htm
that we cannot use "dynamic SOQL can’t use bind variable fields in the query string"
so i just changed my code to
and everything worked fine
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. Best Regards,
Mithun.