-1
global class ABI_SFA_TAC_Removal_Batch implements Database.batchable<sObject>
{    
    // variable decleration.
    public String Query;

     /* 
     Method Name: Start
     Description: This method is used to collect the TAC records ready for deletion.     
    */
    global Database.QueryLocator Start(Database.BatchableContext info)
    { 
       // fetch TAC records ready for removal.

        String Query = 'SELECT ABI_SFA_Account_Removal__c,ABI_SFA_Account__c,ABI_SFA_RecordID__c,ABI_SFA_SHAREID__c, ABI_SFA_Type__c,ABI_SFA_User__c,ABI_SFA_Valid_Till__c,CreatedById,CreatedDate,CurrencyIsoCode,Id,IsDeleted,LastModifiedById,LastModifiedDate,Name,OwnerId,SystemModstamp FROM ABI_SFA_TerritoryAccountChange__c WHERE ABI_SFA_Account__r.name like '%Europromotion%' LIMIT 50000';

       return Database.getQueryLocator(query);  
    }

    /*
     Method Name: Execute
     Description: This method is used to process the TAC records that are passed from Start method.   
    */     
    global void Execute(Database.BatchableContext info, List<ABI_SFA_TerritoryAccountChange__c> tacList)
    {
        if(tacList!=Null && tacList!=Empty){
            System.debug('@@@inside IF block');
            try {
                System.debug('@@@inside TRY block');
                Database.DeleteResult[] TAC_Dels = Database.delete(tacList);
            }
            catch (DmlException e) {
                System.debug('@@@ The following exception has occurred: ' + e.getMessage());
                ApexPages.addMessage(myMsg);
                ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,<strong>string.valueof(e)</strong>); 
            }
        }
    }


    /*
     Method Name: Finish
     Description: This method is used to notify all relevant stakeholders via Email.      
    */       
    global void Finish(Database.BatchableContext info){ 

        String Email;
        List<ID> tacERId = new List<ID>();
        public void SendEmail() {
        for(TACEmailRecipients__c tacER: TACEmailRecipients__c.getAll().values());{
            tacERId.add(tacER.Id);
        }

        EmailTemplate et=[Select id from EmailTemplate where name = 'TAC_Notification' limit 1];

        Messaging.MassEmailMessage mail = new Messaging.MassEmailMessage();
        mail.setTargetObjectIds(tacERId);
        mail.setSenderDisplayName('Acenture Support Team');
        mail.setTemplateId(et.id);
        Messaging.sendEmail(new Messaging.MassEmailMessage[] { mail });
}

    }   
}
3

You have to escape the single quotes after the like operator by using backslash character

 String Query = 'SELECT ABI_SFA_Account_Removal__c,ABI_SFA_Account__c,ABI_SFA_RecordID__c,ABI_SFA_SHAREID__c, ABI_SFA_Type__c,ABI_SFA_User__c,ABI_SFA_Valid_Till__c,CreatedById,CreatedDate,CurrencyIsoCode,Id,IsDeleted,LastModifiedById,LastModifiedDate,Name,OwnerId,SystemModstamp FROM ABI_SFA_TerritoryAccountChange__c WHERE ABI_SFA_Account__r.name like '+'\'%Europromotion%\''+' LIMIT 50000';

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.