function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
GMASJGMASJ 

How to query from a comma separated value in soql

Hi, 

   In custom object Popup_Message__c there is a  custom field  Profile__c which stores comma seprated values now I need a extract a particular value using a soql 

example : In Profile__c is the value is stored as A,B,C

  I want to extract a find if Profile__c = C exit or not. Please suggest me how to extract. 

select Profile__c from Popup_Message__c where Profile__c = 'C' this is not returning 


Thanks 
SUD
Best Answer chosen by GMASJ
Madhukar_HeptarcMadhukar_Heptarc
Hi GMASJ,

In your query you have mentioned Active_Status__c = "Active"  In double Quotes can you please replace like this Active_Status__c = 'Active'
You have to define in Signle quotes for String variable.
List<Popup_Message__c> lstOfMsg = [SELECT Message_Text__c, Start_Date__c, End_Date__c, Active_Status__c, Ordering__c, Profile__c FROM Popup_Message__c WHERE Active_Status__c = 'Active' and (Profile__c like  :('%' + profileName + '%') or Profile__c = null ) and Start_Date__c <= TODAY and End_Date__c >= TODAY Order by Ordering__c];
Let me know any help required 

Thanks &Regards
Madhukar_Heptarc
 

All Answers

Madhukar_HeptarcMadhukar_Heptarc
Hi GMAS,
I have got your requirement.
select Profile__c from Popup_Message__c where Profile__c like '%C'
Can you please  try this Query.
Please let me know if it useful / Any help required.

Thanks & Regards 
Madhukar_Heptarc
Madhukar_HeptarcMadhukar_Heptarc
Hi GMAS,
I have got your requirement.
select Profile__c from Popup_Message__c where Profile__c like '%C%'
Can you please  try this Query.
You can Refer Below  link which explains how to use LIKE funtion :
https://developer.salesforce.com/docs/atlas.en-us.218.0.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_comparisonoperators.htm
Please let me know if it is useful / Any further help required.

Thanks & Regards
Madhukar_Heptarc
 
GMASJGMASJ
Thank Madhukar for you reply I tried you suggestion as mentioned below. 

 
List<Popup_Message__c> lstOfMsg = [SELECT Message_Text__c, Start_Date__c, End_Date__c, Active_Status__c, Ordering__c, Profile__c FROM Popup_Message__c WHERE Active_Status__c = "Active" and (Profile__c like ( :('%' + profileName + '%') or Profile__c = null ) and Start_Date__c <= TODAY and End_Date__c >= TODAY Order by Ordering__c];
I am getting below error in the line please suggest me how to fix. 

User-added image

Thanks
Madhukar_HeptarcMadhukar_Heptarc
Hi GMASJ,
 
List<Popup_Message__c> lstOfMsg = [SELECT Message_Text__c, Start_Date__c, End_Date__c, Active_Status__c, Ordering__c, Profile__c FROM Popup_Message__c WHERE Active_Status__c = "Active" and (Profile__c like  :('%' + profileName + '%') or Profile__c = null ) and Start_Date__c <= TODAY and End_Date__c >= TODAY Order by Ordering__c];
Can you try above query once 

(Or)
can you please try query like this 
String j= '%'+profileName+'%';
List<Popup_Message__c> lstOfMsg = [SELECT Message_Text__c, Start_Date__c, End_Date__c, Active_Status__c, Ordering__c, Profile__c FROM Popup_Message__c WHERE Active_Status__c = "Active" and (Profile__c like  : j or Profile__c = null ) and Start_Date__c <= TODAY and End_Date__c >= TODAY Order by Ordering__c];
Please let me know if it is useful / Any help required.

Thanks & Regards
Madhukar_Heptarc
 
Madhukar_HeptarcMadhukar_Heptarc
Hi GMASJ,

In your query you have mentioned Active_Status__c = "Active"  In double Quotes can you please replace like this Active_Status__c = 'Active'
You have to define in Signle quotes for String variable.
List<Popup_Message__c> lstOfMsg = [SELECT Message_Text__c, Start_Date__c, End_Date__c, Active_Status__c, Ordering__c, Profile__c FROM Popup_Message__c WHERE Active_Status__c = 'Active' and (Profile__c like  :('%' + profileName + '%') or Profile__c = null ) and Start_Date__c <= TODAY and End_Date__c >= TODAY Order by Ordering__c];
Let me know any help required 

Thanks &Regards
Madhukar_Heptarc
 
This was selected as the best answer