Oops! I didn't mean to delete those sObject records! Good news: close that Salesforce support case.
When you delete a sObject record in Salesforce, it's placed into the Recycle Bin for 15 days. They are only permanently deleted after those 15 days.
The undelete
statement is used to restore sObject records from the recycle bin.
This isn't a real-world example, but it illustrates the point:
Lead primaryLead = [SELECT Id FROM Lead WHERE Company = 'Apple Inc']; Lead duplicateLead = [SELECT Id FROM Lead WHERE Company = 'Apple']; merge primaryLead duplicateLead; // duplicateLead is now in the recycle bin undelete duplicateLead;
That's a bit of a silly example. Most of the time, you'll use the ALL ROWS
keyword in SOQL to retrieve the deleted record from the recycle bin. Like so:
public void restoreLeadsByCompany(String companyName){ List<Lead> deletedLeads = [SELECT Id FROM Lead WHERE Company =: companyName ALL ROWS]; undelete deletedLeads; }
This is an undelete
, not an unmerge
. It'll restore records from the Recycle Bin, it won't undo the reparenting that happened during a merge. It does restore some record associations, check out the full list here.