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
Priyanka Reddy 74Priyanka Reddy 74 

System.QueryException: unexpected token: w00000LEFtiAAH

for(Schema.FieldSetMember memberObj : SObjectType.Account.FieldSets.rakch__DemoFieldSet.getFields()){
            qwerty += ','+memberObj.getFieldPath();
        }       

 string id1 = IdList.get(0);
        string id2 = IdList.get(1);

        string query1 = qwerty+' from Account where id=' +id1;
        accList2=Database.query(query1);

Im trying to concate id with query but im getting, can some one let me know where i was going wrong.

ERROR: System.QueryException: unexpected token: w00000LEFtiAAH
Best Answer chosen by Priyanka Reddy 74
Maharajan CMaharajan C
Hi Priyanka,

To concate the id in your query you have to include the single quotes also. And in dynamic query for single quotes we need the escape character.

string query1 = qwerty+ ' from Account where Id = \'' + id1 + '\''; 

https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_quotedstringescapes.htm

Thanks,
Maharajan.C

 

All Answers

Maharajan CMaharajan C
Hi Priyanka,

To concate the id in your query you have to include the single quotes also. And in dynamic query for single quotes we need the escape character.

string query1 = qwerty+ ' from Account where Id = \'' + id1 + '\''; 

https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_quotedstringescapes.htm

Thanks,
Maharajan.C

 
This was selected as the best answer
Priyanka Reddy 74Priyanka Reddy 74
Thank you Maharajan. That worked!