+ 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!