1

How to frame the below dynamic query. Opportunity_User__c field has value in format of "test@gmail.com". Now i want to retrieve all the opportunities having that value using dynamic query.

List<Opportunity> opplist = new List<Opportunity>();  
String Query='SELECT id FROM opportunity Where Opportunity_User__c=\'test@gmail.com\'';
opplist = database.query(Query);

I am getting the below error : "System.QueryException: unexpected token: '@'"

  • Is it the entire query? I don't see any prob in that...I have ran the below query in developer console and i didn't get any syntax error List<Opportunity> opplist = new List<Opportunity>(); String Query='SELECT id FROM opportunity Where Opportunity_User__c=\'test@gmail.com\''; opplist = database.query(Query); – ForceDeveloper Mar 14 '14 at 6:08
  • yes same here ..I dont see any problem .. – Mohith Shrivastava Mar 14 '14 at 6:14
  • Yes the error was not coming now but i can see the records in my system with that value but the records returned was zero. – sunny Mar 14 '14 at 6:21
0

As I understand you try get all emails called 'test' - then try this:

String Query='SELECT id FROM opportunity Where Opportunity_User__c LIKE \'test%\'';

Or this to be more specific:

String Query='SELECT id FROM opportunity Where Opportunity_User__c LIKE \'test_gmail.com\'';
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.