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
anuragsinghnsanuragsinghns 

Batch Class Query

Hi I am writing a batch class to get all contacts where the EmailBouncedDate & EmailBouncedReason fields should be null.I am having a hard time saving because of the "!=" i am not bale to add the escape sequences correctly could anybody help as to where I am going wrong.

global class BouncedCaseCheck implements Database.Batchable<sObject> {
   public String query;
   global Database.QueryLocator start(Database.BatchableContext BC){
   query='SELECT EmailBouncedDate,EmailBouncedReason,Id FROM Contact'+'WHERE EmailBouncedDate !=\''+ null+'\''+'OR  EmailBouncedReason !=\''+null+'\'';
      return Database.getQueryLocator(query);
   }


Edwin VijayEdwin Vijay
Something like this??

public with sharing class forcetree 
{
 String squery = 'Select Id from User where Name=\'forcetree\'';
 Database.query(squery);
}

anuragsinghnsanuragsinghns

it saves but when I execute the batch I get the following exeption

17:47:08:059 EXCEPTION_THROWN [7]|System.QueryException: unexpected token: !=

Edwin VijayEdwin Vijay
query='SELECT EmailBouncedDate,EmailBouncedReason,Id FROM Contact'+'WHERE EmailBouncedDate !=\'null\''+'OR  EmailBouncedReason !=\'null\'';
Try this
Edwin VijayEdwin Vijay
Just curious. Did it work?