Here's program that restores deleted Hiring Manager records whose last name contains a specified string
public class RestoreHiringManagerRecords { public static void restoreRecords(String lastNameSubstring) { List<Hiring_Manager__c> deletedRecords = [SELECT Id, Name FROM Hiring_Manager__c WHERE IsDeleted = true ALL ROWS]; List<Hiring_Manager__c> matchingRecords = new List<Hiring_Manager__c>();
// Filter the deleted records based on the specified string for (Hiring_Manager__c deletedRecord : deletedRecords) { if (deletedRecord.Name != null && deletedRecord.Name.containsIgnoreCase(lastNameSubstring)) { matchingRecords.add(deletedRecord); } }
if (!matchingRecords.isEmpty()) { // Undelete the matching records List<Id> recordIds = new List<Id>(); for (Hiring_Manager__c matchingRecord : matchingRecords) { recordIds.add(matchingRecord.Id); } List<Database.UndeleteResult> undeleteResults = Database.undelete(recordIds, false);
// Check the undelete results for errors for (Database.UndeleteResult undeleteResult : undeleteResults) { if (!undeleteResult.isSuccess()) { System.debug('Error undeleting record: ' + undeleteResult.getErrors()[0].getMessage()); } } } } }
If you find my answer helpful, please mark it as the best answer.
Can you clarify more on the requirement. What do you meant by restore by specified character?
Thanks,
Here's program that restores deleted Hiring Manager records whose last name contains a specified string
public class RestoreHiringManagerRecords {
public static void restoreRecords(String lastNameSubstring) {
List<Hiring_Manager__c> deletedRecords = [SELECT Id, Name FROM Hiring_Manager__c WHERE IsDeleted = true ALL ROWS];
List<Hiring_Manager__c> matchingRecords = new List<Hiring_Manager__c>();
// Filter the deleted records based on the specified string
for (Hiring_Manager__c deletedRecord : deletedRecords) {
if (deletedRecord.Name != null && deletedRecord.Name.containsIgnoreCase(lastNameSubstring)) {
matchingRecords.add(deletedRecord);
}
}
if (!matchingRecords.isEmpty()) {
// Undelete the matching records
List<Id> recordIds = new List<Id>();
for (Hiring_Manager__c matchingRecord : matchingRecords) {
recordIds.add(matchingRecord.Id);
}
List<Database.UndeleteResult> undeleteResults = Database.undelete(recordIds, false);
// Check the undelete results for errors
for (Database.UndeleteResult undeleteResult : undeleteResults) {
if (!undeleteResult.isSuccess()) {
System.debug('Error undeleting record: ' + undeleteResult.getErrors()[0].getMessage());
}
}
}
}
}
If you find my answer helpful, please mark it as the best answer.