+ Start a Discussion
ramya1ramya1 

unexpected token: 'Project__c'

hi,

              Am trying to make the class dynamic..am getting error at parentQuery...getting unexpected token: 'Project__c'  in which 

Project__c is parent name in the query...

 

 

string parentQuery = 'SELECT Id FROM ' + parentName + ' where id=\'' + parentID + '\'';
 SObject ParentObject = Database.query(parentQuery)[0];

 

thanks in advance...

priyanka.mv26priyanka.mv26

Change the query like string parentQuery = 'SELECT Id FROM ' + parentName + ' where id=: parentID ';

and try..

ramya1ramya1

I even tried it...but getting the same issue

priyanka.mv26priyanka.mv26

I tried to execute your query in developer console and it seems to be working fine for me...

 

I tried the below code..

 

String parentName = 'Employee__c';
String parentID = 'a00D000000IzFdh';
string parentQuery = 'SELECT Id FROM ' + parentName + ' where id=\'' + parentID + '\'';
SObject ParentObject = Database.query(parentQuery)[0];
System.debug('ParentObject='+ParentObject);