+ Start a Discussion
maiyakumaiyaku 

Database Query this error unexpected token

caused by: System.QueryException: unexpected token: '('


 

Public MD_Sales_Group_Initials__c getMSGI(List<ID> SalesRepName){
   
   String MSGIQuery = '';
   
   List<MD_Sales_Group_Initials__c> lstMSGI = New List<MD_Sales_Group_Initials__c> ();
   MD_Sales_Group_Initials__c MSGI = New MD_Sales_Group_Initials__c ();
   
   MSGIQuery = 'Select id,Name,Code__c From MD_Sales_Group_Initials__c Where ID In (' + SalesRepName + ')';

            
            
            List<sObject> Qmsgi = Database.Query(MSGIQuery);

            if(Qmsgi != null && Qmsgi.size()>0){
                for(sObject s: Qmsgi){
                    lstMSGI.add((MD_Sales_Group_Initials__c)s);
                }
            }
   
           if(lstMSGI != null && lstMSGI.size() > 0){ MSGI = lstMSGI[0]; }
   
   Return MSGI;
   }

 MSGIQuery = 'Select id,Name,Code__c From MD_Sales_Group_Initials__c Where ID In (' + SalesRepName + ')';

 

Thank you.

Best Answer chosen by Admin (Salesforce Developers) 
Henry AkpalaHenry Akpala

MSGIQuery = 'Select id,Name,Code__c From MD_Sales_Group_Initials__c Where ID In (' + SalesRepName + ')';

Try using

MSGIQuery = 'Select id,Name,Code__c From MD_Sales_Group_Initials__c Where ID In :  SalesRepName '

 

 

All Answers

Henry AkpalaHenry Akpala

MSGIQuery = 'Select id,Name,Code__c From MD_Sales_Group_Initials__c Where ID In (' + SalesRepName + ')';

Try using

MSGIQuery = 'Select id,Name,Code__c From MD_Sales_Group_Initials__c Where ID In :  SalesRepName '

 

 

This was selected as the best answer
Henry AkpalaHenry Akpala

Actually is there a reason you are not using Set<Id> as you arguement to the method?  Change it to Set<Id> and use the previous recomendation. 

maiyakumaiyaku

OK this work but new ploblem 

 

Too many SOQL queries Limit 201 

 

It hard ploblem