+ Start a Discussion
Iqra TechIqra Tech 

i need to query two values stored in my custom field in my query dynamically

i need to query two values stored in my custom field in my query dynamically 

In my custom object i am having custom field that stores single value like XYZ or multiple values like xyz,ABC now i need to query both values how?
Michael BrumleyMichael Brumley
If I'm understanding correctly, you need to use LIKE and the % wildcard. How involved the query is depends on how consistent the entry format is. Ideally, always have an opening and closing comma - that way you can search for LIKE '%,ABC,%' and not have to worry about what happens when you have ABCD,ABC,123 and they search for ABC. If they can only enter and search for 3-character strings it's not an issue, but if the only rule is to comma-separate you'll have that potential issue with the first and last entries. (One way around that would be to base a formula field on the entry field, and search the formula field instead.)
Iqra TechIqra Tech
@Michael Brumley Thanks for the reply i have one more question what i am getting two values in custom field

ex :- i user might be insert  single value or having more than one values seprated by quama than what to do my current query working fine one single value but when i am getting more than two values it is not working please see this my query

 
return Database.getQueryLocator(
            'select Id,Edition__c,Object__c,Opportunity__c,Opportunity_Id__c,Stage__c,Banner_Name__c,Stand_no__c,Edition_Event_Name__c,Additional_field_3__c,' +
            'Additional_field_2__c,Type_of_Stand__c,Customer_Product__c,Additional_field_4__c,Additional_field_1__c,Contractual_Sq_M__c,Hall__c,Height__c,Width__c,' +
            'Open_Sides__c,Additional_field_6__c,Additional_field_5__c,Phone__c,Website__c,Fax__c,PO_Box__c,Floor_Plan_Stage__c from ' + 
            'Floor_Plan_Mapping__c  order by createdDate DESC limit 1');

can you please make correction in this query 

Edition_Event_Name__c  in this field i am  getting values sometimes xyz or sometimes xyz,ABC or PQR,LMN,EFG like this 
Michael BrumleyMichael Brumley
There's no WHERE clause in your query - if you're not trying to filter the results based on a specific value in the comma-delimited field, I'm not sure I see what the problem is. So far, you're just returning a text field - commas or not, it's no different from any other text field. What exactly are you trying to do here, and what do you mean by "not working"?
Iqra TechIqra Tech
I tried using this wehere clause 'Floor_Plan_Mapping__c where Edition_Event_Name__c =\'XYZ\''); but not getting proper soultion what if came more than one values in Edition_Event_Name__c and user can be insert any kind of values what if then 
Michael BrumleyMichael Brumley
Partial matches in the WHERE clause use LIKE instead of =, and use the % wildcard: %target - ends with target% - starts with %target% - contains So, to use this in your comma-delimited field to find "123" in "ABC,123,XYZ" it would be: WHERE Edition_Event_Name__c LIKE '%,123,%' However - this absolutely requires that the search target includes the commas. And you have the potential problem of a failed match at the start or end if the entire field isn't also wrapped in a pair of commas. In the above case, a search for ,ABC, or ,XYZ, will fail. Assuming users are entering this into a standard text field, you have two choices - either a Validation rule enforcing that there's a starting and ending comma, or the dual-field approach mentioned earlier.