Undelete operation in the trigger will be fired, if you are restoring deleted record from the recycle bin. Example. If you deleted an account record, then it will be moved to recycle bin, if you restore the deleted account record from recycle bin, then undelete event in account object will get triggered.
trigger Account_UnDelete on Account (after undelete) {
Account[] theAccount= [select undeleted__c from Account where id in :trigger.new];
for(Account undeletedAccount : theAccount){
undeletedAccount.undeleted__c = true;
}
update theAccount;
}
Undelete operation in the trigger will be fired, if you are restoring deleted record from the recycle bin. Example. If you deleted an account record, then it will be moved to recycle bin, if you restore the deleted account record from recycle bin, then undelete event in account object will get triggered.
trigger Account_UnDelete on Account (after undelete) {
Account[] theAccount= [select undeleted__c from Account where id in :trigger.new];
for(Account undeletedAccount : theAccount){
undeletedAccount.undeleted__c = true;
}
update theAccount;
}
The after undelete trigger event only works with recovered records—that is, records that were deleted and then recovered from the Recycle Bin through the undelete DML statement. These are also called undeleted records.
The after undelete trigger events only run on top-level objects. For example, if you delete an Account, an Opportunity may also be deleted. When you recover the Account from the Recycle Bin, the Opportunity is also recovered. If there is an after undelete trigger event associated with both the Account and the Opportunity, only the Account after undelete trigger event executes.
The after undelete trigger event only fires for the following objects:
Undelete operation in the trigger will be fired, if you are restoring deleted record from the recycle bin. Example. If you deleted an account record, then it will be moved to recycle bin, if you restore the deleted account record from recycle bin, then undelete event in account object will get triggered.
Hope this helps you!
Thanks and Regards
Sandhya
All Answers
List<Account> accountUpdateList = new List<Account>();
if(trigger.isAfter && trigger.isdelete){
for(account c : trigger.old){
Account accountObject = new Account();
accountObject.Id = c.Id;
accountObject.srinivasreddy__deletedby__c = userinfo.getName();
accountUpdateList.add(accountObject);
}
if(!accountUpdateList.isEmpty()){
update accountUpdateList;
}
}
if(trigger.isafter && trigger.isundelete){
for(account aa:trigger.new){
if(aa.srinivasreddy__deletedby__c == userinfo.getName()){
aa.addError('You cannot undelete this record');
}
}
}
}
do this
Undelete operation in the trigger will be fired, if you are restoring deleted record from the recycle bin. Example. If you deleted an account record, then it will be moved to recycle bin, if you restore the deleted account record from recycle bin, then undelete event in account object will get triggered.
Hope this helps you!
Thanks and Regards
Sandhya
The after undelete trigger event only works with recovered records—that is, records that were deleted and then recovered from the Recycle Bin through the undelete DML statement. These are also called undeleted records.
The after undelete trigger events only run on top-level objects. For example, if you delete an Account, an Opportunity may also be deleted. When you recover the Account from the Recycle Bin, the Opportunity is also recovered. If there is an after undelete trigger event associated with both the Account and the Opportunity, only the Account after undelete trigger event executes.
The after undelete trigger event only fires for the following objects:
- Account
- Asset
- Campaign
- Case
- Contact
- ContentDocument
- Contract
- Custom objects
- Event
- Lead
- Opportunity
- Product
- Solution
- Task
TriggerLet us know if this will help you
Thanks
Amit Chaudhary