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
Aaron2010Aaron2010 

SOQL: Using Like -- {URGENT}

Hello everyone,

                             In the following piece of code I am unable to fetch the rows if the groupName consists of left open paranthesis '('  and right open paranthesis ')'.

 

for Eg: if groupName = Assisted Health program (AHP) Japan

 If i remove (AHP) then it is working fine. like if i have my groupname as 'Assisted Health Program'. I am able to fetch the rows.

 

So, how to fetch the rows even if it consists of paranthesis in the groupName?

 

 

 

this.groupName = ApexPages.currentPage().getParameters().get('group');
if (groupName != null) {
evs = [Select Time_Zone_Offset__c, Start_Time__c, Start_Date__c, Name, Id, End_Time__c From Offmax_cal__c where Business__c like :(groupName + '%')];
Best Answer chosen by Admin (Salesforce Developers) 
Aaron2010Aaron2010

Thank you all for the responses... Finally i was able to achieve my requirement by adding (OR Business__c = :groupName) to soql query. But for some reason i am not able to put the groupName after Like because it was not fetching any rows.

 

Eg: groupName = 'Natural Surgery (NS)' --> If i keep this after like in where clause it was not fetching any rows... but if i use     

       Bussiness__c = :groupName i am able to fetch the rows.

 

Modified query that is working for me....

 

this.groupName = ApexPages.currentPage().getParameters().get('group');

if (groupName != null)
{
  string tgroupName = '(' + groupName + '%)';
  evs = [Select Time_Zone_Offset__c, Start_Time__c, Start_Date__c, Name, Id, End_Time__c  From Offmax_cal__c where Business__c like :tgroupName OR Business__c = :groupName];
}

 

 

All Answers

rscottrscott

This seems to work for me as written. Can you verify what the variable groupName contains right before you run your select? 

bbrantly1bbrantly1

Try:

 

 

this.groupName = ApexPages.currentPage().getParameters().get('group');

if (groupName != null) 
{
  string tgroupName = '(' + groupName + '%)';
  evs = [Select Time_Zone_Offset__c, Start_Time__c, Start_Date__c, Name, Id, End_Time__c  From Offmax_cal__c where Business__c like :tgroupName];
}

 

 

Aaron2010Aaron2010

Thank you all for the responses... Finally i was able to achieve my requirement by adding (OR Business__c = :groupName) to soql query. But for some reason i am not able to put the groupName after Like because it was not fetching any rows.

 

Eg: groupName = 'Natural Surgery (NS)' --> If i keep this after like in where clause it was not fetching any rows... but if i use     

       Bussiness__c = :groupName i am able to fetch the rows.

 

Modified query that is working for me....

 

this.groupName = ApexPages.currentPage().getParameters().get('group');

if (groupName != null)
{
  string tgroupName = '(' + groupName + '%)';
  evs = [Select Time_Zone_Offset__c, Start_Time__c, Start_Date__c, Name, Id, End_Time__c  From Offmax_cal__c where Business__c like :tgroupName OR Business__c = :groupName];
}

 

 

This was selected as the best answer