Skip to content

Instantly share code, notes, and snippets.

@swapnilshrikhande
Created November 27, 2021 10:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save swapnilshrikhande/d97773d4ace957a515e6997b5ae627f2 to your computer and use it in GitHub Desktop.
Save swapnilshrikhande/d97773d4ace957a515e6997b5ae627f2 to your computer and use it in GitHub Desktop.
Undeleting Records In Apex (Salesforce)
List<Contact> contactsToUnDelete = new List<Contact>();
for(Contact c : [Select Id, Name, IsDeleted from Contact LIMIT 50000 ALL ROWS]){
if( c.IsDeleted == true ) {
System.debug('Undeleting Contact ='+c.Name+' : '+c.IsDeleted);
contactsToUnDelete.add(c);
}
}
if( contactsToUnDelete.size() > 0 ){
System.debug('Undeleting In Total '+contactsToUnDelete.size()+' Contacts');
undelete contactsToUnDelete;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment