You can try the following query to undelete the record from Recycle bin:
List<Account> lstAcc = [SELECT Id FROM Account WHERE IsDeleted = true];
system.debug('Deleted Record list is'+lstAc);
undelete lstAcc;
I did not use ALL ROWS here in query, since ALL ROWS pull all the deleted record from the system but the records only from recycle bin can be un deleted, rest you can not un delete though query returns them.
Account a = new Account();
a.Name='Universal Containers';
insert(a);
Contact c = new Contact();
c.LastName='Carter';
c.AccountId=a.Id;
delete a;
Account[] savedAccts = [SELECT Id, Name FROM Account WHERE Name = 'Universal Containers' ALL ROWS];
try {
Database.undelete(savedAccts,false);
} catch (DmlException e) {
// Process exception here
}
If you want to undelete specific records use Recycle bin to undelete or you can run above query in Execute anonymous window with specfic where conditions like deleted by, deleted date,name..
<pre>
undelete [SELECT Id FROM Account WHERE IsDeleted = true ALL ROWS];
</pre>
Please try this code and check all previous questions which you have the post.
mark as solve which may help others.
trigger UnDeleteRecordTrigger on Account (after undelete) {
if(Trigger.isAfter && Trigger.isUndelete) {
List<Account> accListToUpdate = new List<Account>();
Set<Id> accidset = new Set<Id>();
for(Account acc: Trigger.New){
accidset.add(acc.Id);
}
system.debug('accidset--> '+accidset);
List<Account> accNewList = [Select Id, Name From Account Where Id=:accidset limit 1];
for(Account ac: accNewList){
ac.Name = 'Undeleted'+ ac.Name;
accListToUpdate.add(ac);
}
update accListToUpdate;
}
}
Please let me know if you have any query.
Please mark it as best Answer if you find it helpful.
Thank You
Ajay Dubedi
You can try the following query to undelete the record from Recycle bin:
I did not use ALL ROWS here in query, since ALL ROWS pull all the deleted record from the system but the records only from recycle bin can be un deleted, rest you can not un delete though query returns them.
Mark answer as solved if does help you.
Try this code:
Please make it best if it helps you.
Thanks
Akshay