You need to sign in to do that
Don't have an account?
SVsfdc
SOQL Query for Checklist type using LIKE operator
Please help me on SOQL query using Like operator for Checklist Type in SF.
SELECT Order_Type__c,Part_number__c FROM Product where Order_Type__c 'Purchase%'
The below values are for Order_type__c field.
Annual Lease;Purchase;Short Term Lease
Fee
Lease
Lease;Purchase
Lease;Purchase;Short Term Lease
SELECT Order_Type__c,Part_number__c FROM Product where Order_Type__c 'Purchase%'
The below values are for Order_type__c field.
Annual Lease;Purchase;Short Term Lease
Fee
Lease
Lease;Purchase
Lease;Purchase;Short Term Lease
Please use below.
String str='Lease;Purchase;Short Term Lease';
String queryStr = 'SELECT Order_Type__c,Part_number__c FROM Product2 where Order_Type__c includes(\''+str+'\')';
System.debug(queryStr);
List<Product2> plist= Database.query(queryStr);
System.debug(plist);
All Answers
What query you suggest If I'm using Developer Console?
I'm getting the below error 'Unknown error parsing query'
System.debug('plist size:'+plist.size());
Click on DEBUG > Open Execute anonymous window > paster the above two statements > click on execute > you can find the results in log's tab
Hope it helps!
Part_number__c FROM Product2 where Order_Type__c LIKE :('%' + str + ^ ERROR at Row:1:Column:57 invalid operator on multipicklist field
String str='Lease;Purchase;Short Term Lease';
List<Product2> plist=[SELECT Order_Type__c,Part_number__c FROM Product2 where Order_Type__c includes :str];
https://help.salesforce.com/articleView?id=000211744&type=1
Please try below
String str='Lease;Purchase;Short Term Lease';
List<Product2> plist=[SELECT Order_Type__c,Part_number__c FROM Product2 where Order_Type__c includes('Lease;Purchase;Short Term Lease')];
Thank you Pawan this new query worked.
You are getting that error because Includes operator does not supports bind varaibles(:VarName) concepts.
So please try below and let me know the output. Here i am using dynaic SQL in order to make str dynamic.
String str='Lease;Purchase;Short Term Lease';
String queryStr = 'SELECT Order_Type__c,Part_number__c FROM Product2 where Order_Type__c includes('+str+')';
List<Product2> plist= Database.query(queryStr);
System.debug(plist);
Please use below.
String str='Lease;Purchase;Short Term Lease';
String queryStr = 'SELECT Order_Type__c,Part_number__c FROM Product2 where Order_Type__c includes(\''+str+'\')';
System.debug(queryStr);
List<Product2> plist= Database.query(queryStr);
System.debug(plist);
Thank you somuch Pawan and also Bala and Govind.
I'm new to Sf and I learned how to handle Type Checklist.