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
Kumar Saurav 16Kumar Saurav 16 

Error: Compile Error: Found punctuation symbol or operator '%' that isn't valid in Apex. at line 14 column 362

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 });
}
                 
    }   
}

 
Best Answer chosen by Kumar Saurav 16
SEKAR RAJ.SEKAR RAJ.
Hi Kumar,
Change the query where condition like below ,
String Query = 'SELECT ABI_SFA_Account_Removal__c FROM ABI_SFA_TerritoryAccountChange__c WHERE ABI_SFA_Account__r.name like 'Europromotion%'  LIMIT 50000';


Thanks,
SEKAR RAJ

All Answers

SEKAR RAJ.SEKAR RAJ.
Hi Kumar,
Change the query where condition like below ,
String Query = 'SELECT ABI_SFA_Account_Removal__c FROM ABI_SFA_TerritoryAccountChange__c WHERE ABI_SFA_Account__r.name like 'Europromotion%'  LIMIT 50000';


Thanks,
SEKAR RAJ
This was selected as the best answer
Raj VakatiRaj Vakati
Use this SOQL
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';

IN Dynamic SOQL use of wildcards and the term 'Like' below 
 
String query = 'SELECT Id, Name FROM Account WHERE name LIKE \'%' + searchVar + '%\'';
List<Account> accts = Database.query(query);


or using Apex Variables in case of SOQL use of wildcards and the term 'Like' below
 
List<Account> accts = [SELECT Id, Name FROM Account WHERE name LIKE :('%' + searchName + '%')];



Complete code 



 
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 });
}
                 
    }   
}