You need to sign in to do that
Don't have an account?
System.QueryException: unexpected token: ')' in Dynamic SOQL
Hi Guys,
---------------Code Snippet---------------------
String mystring= String.ValueOF('sa.Site_CX__r.name=:solutionSite1 OR sa.Site_CX__r.name=:solutionSite2 OR sa.Site_CX__r.name=:solutionSite3');
lstSiteApp = Database.query('select id,Site_Application_List__c,Application_Id__c,Site_CX__r.name from Site_Application__c sa where \n'+
'sa.Application_Id__c IN(select sma.Application_ID__c from Service_Model_Application__c sma where Service_Model_ID__c=:selectedServiceModel2)\n'+
'AND (mystring) AND sa.id NOT IN(select sd.Site_Application_ID__c from Solution_Detail__c sd where sd.Solution_ID__r.id=:recordid2)\n'+
'ORDER BY Site_Application_List__c');
---------------------------------------------------------------------------
When i am using sa.Site_CX__r.name=:solutionSite1 OR sa.Site_CX__r.name=:solutionSite2 OR sa.Site_CX__r.name=:solutionSite3 directly in place of mystring,code is working fine(using this will not solve the purpose of Dynamic SOQL).
If I use mystring,Error:System.QueryException: unexpected token: ')' is coming.
Please help.
Hi Gaurav,
You have to update your dynamic SOQL with following.
Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator
All Answers
Hi Gaurav,
You have to update your dynamic SOQL with following.
Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator
Hi Hitesh,
Thanks for your solution.This is working.
Regards,
Gaurav
Hi Hitesh,
One more query on this:
I am adding String Yes,but System is thowing exception.
--------------Code------------------
mystring = mystring + ' AND sa.Site_CX__r.FGSS__c= ' + ' Yes ';
Error:
System.QueryException: unexpected token: 'Yes'
How can I add Yes to this?
Hi Gaurav,
Try to use below code
mystring = mystring + ' AND sa.Site_CX__r.FGSS__c= Yes ';
Hitesh,
Its not working,showing same error.
what is the data type of FGSS__c field?
Its of type Text.
Then try to use following
mystring = mystring + ' AND sa.Site_CX__r.FGSS__c= \'Yes\' ';
Thanks for your reply Hitesh:) .Its working .You rock Man.