Created
November 27, 2021 10:31
-
-
Save swapnilshrikhande/d97773d4ace957a515e6997b5ae627f2 to your computer and use it in GitHub Desktop.
Undeleting Records In Apex (Salesforce)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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