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
PAWAN THOSARPAWAN THOSAR 

Write an apex program, to re-store the Hiring Manager Records back to the object, based on the specified characters at runtime.

Sai PraveenSai Praveen (Salesforce Developers) 
Hi Pawan,

Can you clarify more on the requirement. What do you meant by restore by specified character?

Thanks,
 
Prateek Prasoon 25Prateek Prasoon 25
Hey Pawan,

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.