You need to sign in to do that
Don't have an account?

Error Apex Code
I want to delete dupicate accounts below code for your reference. Attached is the error
global class DuplicateRecords implements Database.Batchable<SObject> {
Global Map<String , Account__c> AccountNumberBookmap = new Map<String , Account__c>();
global Database.QueryLocator start(Database.BatchableContext BC){
return Database.getQueryLocator([Select AccountNumber__c from Account__c where AccountNumber__c != null]);
}
global void excute(Database.BatchableContext BC , List<AccountNumber__c> scope){
// Map<String , AccountNumber__c> AccountBookmap = new Map<String , AccountNumber__c>();
List<AccountNumber__c> duplicatelist = new List<AccountNumber__c>();
for(AccountNumber__c s : scope){
if(! AccountBookmap.containsKey(s.Account__c)){
AccountBookmap.put(s.Account__c , s);
}
else{
duplicatelist.add(s);
}
}
system.debug(duplicatelist);
if(duplicatelist.size() > 0){
delete duplicatelist;
}
}
global void finish(Database.BatchableContext BC){
}
}

global class DuplicateRecords implements Database.Batchable<SObject> {
Global Map<String , Account__c> AccountNumberBookmap = new Map<String , Account__c>();
global Database.QueryLocator start(Database.BatchableContext BC){
return Database.getQueryLocator([Select AccountNumber__c from Account__c where AccountNumber__c != null]);
}
global void excute(Database.BatchableContext BC , List<AccountNumber__c> scope){
// Map<String , AccountNumber__c> AccountBookmap = new Map<String , AccountNumber__c>();
List<AccountNumber__c> duplicatelist = new List<AccountNumber__c>();
for(AccountNumber__c s : scope){
if(! AccountBookmap.containsKey(s.Account__c)){
AccountBookmap.put(s.Account__c , s);
}
else{
duplicatelist.add(s);
}
}
system.debug(duplicatelist);
if(duplicatelist.size() > 0){
delete duplicatelist;
}
}
global void finish(Database.BatchableContext BC){
}
}
You can remove the error by using below code. I have tested it in my org. It is working fine.
'I am assuming that you have made a custom Account__c in your org.' if you are working on standard Account object, make sure to remove '__c' from Account and AccountNumber in the code.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
You have not implemented execute method in this batch class. Its showing error in problems section in your screenshot. Please correct spelling of execute in your code.
Thanks
Please check below code . It will help .
I have added one extra line while we need to check the map empty else it will always add the first account to the duplicate list .
Also as we are doing the delete operation in finish method we need to have state ful to maintain the state of the map .
Check incase workin let me know .
Thanks
Manoj