Loading

Cannot Recover a Deleted Salesforce Apex Class or Trigger

게시 일자: May 23, 2026
상세 설명

In Salesforce, once an Apex class or Apex trigger is permanently deleted from an org, it cannot be recovered. Salesforce does not maintain a recycle bin or restore mechanism for Apex code metadata. This is different from Salesforce record deletion, where the Recycle Bin allows recovery within 15 days. To prevent data loss, developers must maintain their own backups of all Apex code.

솔루션

Why Apex Code Cannot Be Recovered

Apex classes and triggers are stored as metadata in the Salesforce metadata repository. When deleted, they are immediately and permanently removed from the metadata layer. Salesforce Support cannot restore deleted Apex code through any process.

Best Practice: Maintain Code Backups

Developers are strongly encouraged to maintain up-to-date backups of all Apex code. Recommended approaches:

  1. Version Control System (VCS): Use a tool such as Git to track all Apex code in a repository (e.g., GitHub, GitLab, or Bitbucket). This is the most reliable backup strategy.
  2. Salesforce CLI: Run the command sf project retrieve start regularly to export org metadata to your local development environment.
  3. Salesforce DX and Unlocked Packages: Use scratch orgs and unlocked packages to store Apex code in version-controlled source format.

Preventing Accidental Deletion

Before deleting any Apex class or trigger in a production org, ensure the code is backed up. Make all metadata changes in a Sandbox first and deploy using change sets or Salesforce CLI after review.

Knowledge 기사 번호

000386045

 
로드 중
Salesforce Help | Article