While trying to insert record into database from recycle bin:

For ex, I have contact record in my salesforce and i have deleted that contact record, that stored in recycle bin.

After deleting the contact record, i have created new record in contact object (as it is deleted contact record has information like, first name, last name, email previously deleted record from contact).

I have written a trigger for contact object, that is while inserting new contact fire error, if first name, last name, email is there.

my question is.... Can i restore the contact record from recycle bin already existing same details in contact object?

In that time, trigger will fire or not?

How can I write trigger to restore records from the recycle bin?

Which context variable can I have to use?

1 Answer 1


This Triggers documentation explains that:

A trigger is Apex code that executes before or after the following types of operations:


For example, you can have a trigger run before an object's records are inserted into the database, after records have been deleted, or even after a record is restored from the Recycle Bin.

So you can write a trigger that performs custom logic for an object type when it is restored from the Recycle Bin by handling the after undelete trigger event. Think through your current Contact trigger and work out how to incorporate the new after undelete logic to achieve what you want.

  • After restoring records from undelete does the record have new id or the old one?
    – Yamini
    Jul 12, 2022 at 5:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .