function readOnly(count){ }
Don't have an account?
Search for an answer or ask a question of the zone or Customer Support.
You need to sign in to do that
Sign in to start searching questions
Signup for a Developer Edition
Sign in to start a discussion
public class deleteinActiveAccountContact implements Database.Batchable<sObject> { public Database.QueryLocator start(Database.BatchableContext bc) { return Database.getQueryLocator('SELECT id FROM Account where IsActive__c = false'); } public void execute(Database.BatchableContext bc, List<Account> records){ Set<String> AccIds = new set<String>(); for(Account Acc : records){ if(Acc.IsActive__c == false){ AccIds.add(Acc.id); } } list<Contact> lstCon = [Select id,AccountId From Contact where AccountId In :AccIds ]; If(lstCon.size()>0){ delete lstCon; } } public void finish(Database.BatchableContext bc){ Id job = bc.getJobId(); } }
try Below Batch Class Please Mark It As Best Answer If It Helps
Thank You!
All Answers
try Below Batch Class Please Mark It As Best Answer If It Helps
Thank You!
please try below batch class code :
public class inactiveAccountContactDelete implements Database.Batchable<sObject> {
public Database.QueryLocator start(Database.BatchableContext bc) {
return Database.getQueryLocator('SELECT id FROM Account WHERE IsActive__c = false');
}
public void execute(Database.BatchableContext bc, List<Account> accountList){
Set<String> accountIds = new set<String>();
for(Account eachAccount : accountList){
if(eachAccount.IsActive__c == false){
accountIds.add(eachAccount.id);
}
}
List<Contact> contactList = new List<Contact>();
contactList = [SELECT id, name, AccountId FROM Contact WHERE AccountId In : accountIds];
If(contactList.size()>0){
delete contactList;
}
}
public void finish(Database.BatchableContext bc){
Id job = bc.getJobId();
}
}
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Suraj
Please Close Your Query By Marking It As Best Answer If It Helps.So It Also Helps Others In Future
Thank You!