Hi,
Can somebody help me in bulkifying the below code? I am learning Apex and I tried writing the below code to delete the record after some automation was done.
Kindly suggest your inputs to proceed further.
Thanks,
public without sharing class MergeDuplicateClientRecord {
public static List<Boolean> hardDeleteDuplicateRecord(List<String> duplicateIds) {
List<Boolean> isSuccess = new List<Boolean>();
Boolean isDeleted = false;
Database.emptyRecycleBinResult result;
Database.deleteResult sr;
if( duplicateIds != NULL && duplicateIds.size() > 0 && String.isNotBlank( duplicateIds[ 0 ] ) ) {
Account acc = new Account(Id = duplicateIds[ 0 ]);
sr = Database.Delete(acc);
result = Database.emptyRecycleBin(acc);
}
if( ( sr != NULL && sr.isSuccess() ) && ( result != NULL && result.isSuccess() ) )
isDeleted = true;
isSuccess.add( isDeleted );
return isSuccess;
}
}
public without sharing class MergeDuplicateClientRecord {
public static List<Boolean> hardDeleteDuplicateRecord(List<String> duplicateIds) {
if( duplicateIds != NULL && duplicateIds.size() > 0){
Database.deleteResult sr;
List<Account> accLstToDelete = new List<Account>();
For(String str:duplicateIds){
accLstToDelete.add(new Account(Id = str));
}
Database.DeleteResult[] DR_Dels = Database.delete(accLstToDelete);
if(sr.isSuccess())
return true;
}
return false;
}
}