function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rakhi B 10Rakhi B 10 

Undelete the account record using trigger

Best Answer chosen by Rakhi B 10
Narender Singh(Nads)Narender Singh(Nads)
Hi,
To undelete an account record, you can do a SOQL query to get the deleted records like this:
Account  DeletedAccount=[select id from contact where name='YOUR_ACCOUNT_NAME ' limit 1 ALL ROWS ];

Then you can use 'undelete' operation to undelete that record:
Undelete DeletedAccount;

Please note that the code structure of the trigger will depend on what functionality are you trying to achieve.
 

All Answers

Narender Singh(Nads)Narender Singh(Nads)
Hi,
To undelete an account record, you can do a SOQL query to get the deleted records like this:
Account  DeletedAccount=[select id from contact where name='YOUR_ACCOUNT_NAME ' limit 1 ALL ROWS ];

Then you can use 'undelete' operation to undelete that record:
Undelete DeletedAccount;

Please note that the code structure of the trigger will depend on what functionality are you trying to achieve.
 
This was selected as the best answer
Ajay K DubediAjay K Dubedi
Hi Rakhi,

As I can see Narender is using account object to get records but in the query and he is using Contact object.
The error he will get is invalid type Account.
I don't think it works. Please review the code.

Thank You
Ajay Dubedi
Narender Singh(Nads)Narender Singh(Nads)
Ohh! Silly me.
The query should be:
Account  DeletedAccount=[select id from account where name='YOUR_ACCOUNT_NAME ' limit 1 ALL ROWS ];

Thanks Ajay for pointing it out!