+ Start a Discussion
Venkata Sravan Kumar BandariVenkata Sravan Kumar Bandari 

this query is not executing please help me...?


soql = 'select name, student_id__c, qualification__c, email__c from name__c where name LIKE :'+String.escapeSingleQuotes(studentName)+'%';
Best Answer chosen by Venkata Sravan Kumar Bandari
Venkata Sravan Kumar BandariVenkata Sravan Kumar Bandari
I got the solution
 
soql = 'select name, student_id__c, qualification__c, email__c from name__c where name LIKE \''+String.escapeSingleQuotes(studentName)+'%\'';

 

All Answers

Frédéric TrébuchetFrédéric Trébuchet
Do you mean:
soql = 'select name, student_id__c, qualification__c, email__c from name__c where name LIKE '%'+String.escapeSingleQuotes(studentName)+'%';
I've replaced :' at the beginning by '%'.

Hope this helps,
Fred
 
Venkata Sravan Kumar BandariVenkata Sravan Kumar Bandari
Thank you for ur reply, but my requirement not like that
Frédéric TrébuchetFrédéric Trébuchet
explain
Frédéric TrébuchetFrédéric Trébuchet
For dynamic SOQL you cannot have bind variables. So, you have to translate them to string first.
Maybe this should work:
soql = 'select name, student_id__c, qualification__c, email__c from name__c where name LIKE ' + String.escapeSingleQuotes(studentName) + '%';
Also referer to dynamic SOQL for more information http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_dynamic_soql.htm.

Regards,
Fred
Venkata Sravan Kumar BandariVenkata Sravan Kumar Bandari
I got the solution
 
soql = 'select name, student_id__c, qualification__c, email__c from name__c where name LIKE \''+String.escapeSingleQuotes(studentName)+'%\'';

 
This was selected as the best answer