You need to sign in to do that
Don't have an account?

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 + '%')];
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
This seems to work for me as written. Can you verify what the variable groupName contains right before you run your select?
Try:
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];
}