+ Start a Discussion
Balu_devBalu_dev 

Unable to put Semi Join Query in a String--Error"System.QueryException: unexpected token: IN"

I am having issues including this below query in a string.

 

String Query = 'Select Id, Discount__c from item1__c Where Id'+

'IN(Select item1__c,Product__c From Item2__c where'+ 'Product__c >0)'+

'and Id IN(Select Item1__c,Account_Id__c From Item3__c where active__c >0)';

 

Urgent help will be appreciated...Thanks..

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Starz26Starz26

You issue in in the Where I IN Select queries. You cannot have multiple field in the queries as you are only looking at one field:

 

Select Id, Discount_Rollup__c, Car_Van_Type__c from Line_item__c 

Where Id IN (Select Line_item__c,Product__c, Product_Key_Model_Discount_Level__c, Product_Key_Model__c From 

Line_Item_Product__c where Product_Key_Model__c >0)

and Id IN (Select Line_Item__c,Discount__c, Account_Id__c From Deal_Line_Item__c where deal_active__c >0)

 

change it to:

 

Select Id, Discount_Rollup__c, Car_Van_Type__c from Line_item__c 

Where Id IN (Select Line_item__c From 

Line_Item_Product__c where Product_Key_Model__c >0)

and Id IN (Select Line_Item__c where deal_active__c >0)


All Answers

jaxdmasterjaxdmaster
String Query = 'Select Id, Discount__c from item1__c Where Id '+
'IN (Select item1__c From Item2__c where'+ 'Product__c >0)'+
'and Id IN(Select Item1__c From Item3__c where active__c >0)';

 try this above query. It should work. 

Starz26Starz26

 Spacing is the issue... The post above has one additional spacing issue that will cause an error. (**See following posts as can only have 1 fiel in where selects)

 

try

 

String Query = 'Select Id, Discount__c from item1__c Where Id'+
' IN (Select item1__c,Product__c From Item2__c where Product__c >0)'+
' and Id IN (Select Item1__c,Account_Id__c From Item3__c where active__c >0)';

 

Balu_devBalu_dev

Public String query ='Select Id, Discount_Rollup__c, Car_Van_Type__c from Line_item__c Where Id '+
'IN (Select Line_item__c,Product__c, Product_Key_Model_Discount_Level__c, Product_Key_Model__c'+
'From Line_Item_Product__c where Product_Key_Model__c >0)'+
'and Id IN(Select Line_Item__c,Discount__c, Account_Id__c From Deal_Line_Item__c where deal_active__c >0)';

 

This is my exact query, now when i run test it says error-System.QueryException: unexpected token: ,

 

I could'nt find what mistake i have done..plz let me kw..

Balu_devBalu_dev

Public String query ='Select Id, Discount_Rollup__c, Car_Van_Type__c from Line_item__c Where Id '+
'IN (Select Line_item__c,Product__c, Product_Key_Model_Discount_Level__c, Product_Key_Model__c'+
'From Line_Item_Product__c where Product_Key_Model__c >0)'+
'and Id IN(Select Line_Item__c,Discount__c, Account_Id__c From Deal_Line_Item__c where deal_active__c >0)';

 

This is my exact query, now when i run test it says error-System.QueryException: unexpected token: ,

 

I could'nt find what mistake i have done..plz let me kw..

Balu_devBalu_dev

Now i changed the query into a single line like this :

'Select Id, Discount_Rollup__c, Car_Van_Type__c from Line_item__c Where Id IN (Select Line_item__c,Product__c, Product_Key_Model_Discount_Level__c, Product_Key_Model__c From Line_Item_Product__c where Product_Key_Model__c >0)and Id IN (Select Line_Item__c,Discount__c, Account_Id__c From Deal_Line_Item__c where deal_active__c >0)';

 

I am getting below error :

 

System.QueryException: unexpected token: ,

 

Any help will be appreciated..Thanks.

Starz26Starz26

You issue in in the Where I IN Select queries. You cannot have multiple field in the queries as you are only looking at one field:

 

Select Id, Discount_Rollup__c, Car_Van_Type__c from Line_item__c 

Where Id IN (Select Line_item__c,Product__c, Product_Key_Model_Discount_Level__c, Product_Key_Model__c From 

Line_Item_Product__c where Product_Key_Model__c >0)

and Id IN (Select Line_Item__c,Discount__c, Account_Id__c From Deal_Line_Item__c where deal_active__c >0)

 

change it to:

 

Select Id, Discount_Rollup__c, Car_Van_Type__c from Line_item__c 

Where Id IN (Select Line_item__c From 

Line_Item_Product__c where Product_Key_Model__c >0)

and Id IN (Select Line_Item__c where deal_active__c >0)


This was selected as the best answer
Balu_devBalu_dev

Thanks..

Balu_devBalu_dev

Thanks