Thursday 23 May 2013


Delete and Undelete

Delete and Undelete statements move up to 200 records of the same object type to and
from the Recycle Bin, respectively. Listing 5-36 shows an example of the Delete statement.
A new Resource record named Terry is added and then deleted.

Listing 5-36 Deleting Records

Resource__c terry = new Resource__c(Name = 'Terry Bull');
insert terry;
delete terry;


Listing 5-37 builds on Listing 5-36 to undelete the Terry record. Concatenate the listings
in the Execute Anonymous view to test.The database is queried to prove the existence
of the undeleted record.Try running the code a second time with the undelete
statement commented out to see that it is working as intended.


Listing 5-37 Undeleting Records
undelete terry;
Resource__c terry2 = [ SELECT Id, Name
FROM Resource__c WHERE Name LIKE 'Terry%' LIMIT 1 ];
System.debug(terry2.Name + ' exists');
delete terry;

No comments:

Post a Comment