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
Andy Kallio 7Andy Kallio 7 

This works in Query Editor but not Execute Anonymous

Hello friends,
This query returns results when I run it developer console's Query Editor and the Workbench's Query Editor.
 
select Id, Name, Campaign_Name__c, RecordType.Name from Campaign__c where Campaign_Name__c LIKE '%\_%'


However, when I try to use it in Execute Anonymous it returns nothing. I've also tried using // instead of / . 

 

Has anybody else run into this?

Best Answer chosen by Andy Kallio 7
GCKGCK
Hello Andy,

Try as below,this would work.

String query ='SELECT Id, Name, Campaign_Name__c, RecordType.Name from Campaign__c where Campaign_Name__c LIKE \'%\\_%\'';
List<Campaign__c> details = Database.query(query);
system.debug('Details--'+details);

Thanks, 

All Answers

Athira PUAthira PU
Hey Andy 

Try out this 
SELECT Name,id FROM Account WHERE Name LIKE 'fa%'
The following query matches farsana,faisal,fathima not feona and in LIKE statement you can pass only a single word or matching char like 'fa'

Thanks
Athira.P.U
GauravendraGauravendra
Hi Andy,

Please store the result of SOQL query in List <Campaign__c>.
Try priniting it out using debug log, you will able ot see the result.

Hope that helps!
GCKGCK
Hello Andy,

Try as below,this would work.

String query ='SELECT Id, Name, Campaign_Name__c, RecordType.Name from Campaign__c where Campaign_Name__c LIKE \'%\\_%\'';
List<Campaign__c> details = Database.query(query);
system.debug('Details--'+details);

Thanks, 
This was selected as the best answer