You need to sign in to do that
Don't have an account?

NOT IN Clause not working for List
I am trying to Accounts with following dynamic soql :
query= 'select Account_vod__c,Account_vod__r.Id,Account_vod__r.Name,Address_line_2_vod__c,'+
'City_vod__c,Name,Primary_vod__c,State_vod__c,Zip_vod__c from Address_vod__c where '+
'Account_vod__r.Name like \'%'+searchByName+'%\' OR City_vod__c=\''+searchByCity+'\' OR '+
'State_vod__c=\''+searchByState+'\' OR Zip_vod__c=\''+searchByZip+'\' OR Name=\''+searchByAddressLine1+'\' AND NOT IN : accIds';
in this accIds is a List of Account Ids which i want to exclude from the return record list. but for this NOT IN Clause is not working. I am getting a query exception for this perticular line . How to solve this problem.
Please help me in this regard, as it is kind of urgent for me.
Hi Annu,
Check this query ,Hope this will help you.
query='select Account_vod__c,Account_vod__r.Id,Account_vod__r.Name,Address_line_2_vod__c,City_vod__c,Name,Primary_vod__c,State_vod__c,Zip_vod__c from Address_vod__c where Account_vod__r.Name like \'%'+searchByName+'%\' OR City_vod__c=\''+searchByCity+'\' OR State_vod__c=\''+searchByState+'\' OR Zip_vod__c=\''+searchByZip+'\' OR Name=\''+searchByAddressLine1+'\' AND accountid NOT IN '+ accIds;
Not getting. .:(
getting this exception : Exception e System.QueryException: unexpected token: '('
Hello,
I think you have forgot to write field name before NOT IN : accIds'; . You must have to specify the field name before this like id not in:accIds. Your query should be like this:
query= 'select Account_vod__c,Account_vod__r.Id,Account_vod__r.Name,Address_line_2_vod__c,'+
'City_vod__c,Name,Primary_vod__c,State_vod__c,Zip_vod__c from Address_vod__c where '+
'Account_vod__r.Name like \'%'+searchByName+'%\' OR City_vod__c=\''+searchByCity+'\' OR '+
'State_vod__c=\''+searchByState+'\' OR Zip_vod__c=\''+searchByZip+'\' OR Name=\''+searchByAddressLine1+'\' AND FieldName NOT IN : accIds';
Note:
Even if you find error in side this than put all the fields together and check the same on Apex Explorar.
Sorry for previous result
query='select Account_vod__c,Account_vod__r.Id,Account_vod__r.Na
me,Address_line_2_vod__c,City_vod__c,Name,Primary_vod__c,State_vod__c,Zip_vod__c from Address_vod__c where Account_vod__r.Name like \'%'+searchByName+'%\' OR City_vod__c=\''+searchByCity+'\' OR State_vod__c=\''+searchByState+'\' OR Zip_vod__c=\''+searchByZip+'\' OR Name=\''+searchByAddressLine1+'\' AND accountid NOT IN :accIds';