Discussion
Pegasystems Inc.
BR
Last activity: 6 Nov 2025 12:50 EST
Best Practices for Pega Class Management: Safely Using Refactoring and Deletion Wizards
Introduction
Managing application integrity and compliance in Pega Cloud environments requires careful attention to how classes and rules are handled. The Pega Platform is a highly metadata-driven system; every action, especially those concerning the data model, must be processed through the platform's internal mechanisms to ensure consistency across the entire system.
In time, we have observed significant issues caused by the practice of database direct class removal. This article aims to share why this approach is not only risky but often a violation of Pega Cloud compliance, and outlines the best practices you should follow to maintain a robust, stable, and supportable application. We invite you to share your own experiences and tips in the comments.
Why You Should Not Remove Classes Directly from the Database
Directly manipulating the underlying database (DB) to remove a class bypasses the Pega Platform's critical layers of abstraction, leading to severe and often difficult-to-diagnose issues.
1. Deep Technical Inconsistency and Metadata Corruption
Pega stores class definitions and rule dependencies across multiple tables, not just a single location. Direct deletion only removes the class record from the primary table (e.g., pr4_base or the table holding the class definition) but leaves behind orphaned records in crucial metadata tables.
| Metadata Component | Impact of Direct DB Deletion |
Consequence |
|---|---|---|
| Rule Cache | The in-memory cache is not invalidated, leading to the system attempting to load a non-existent class. | ClassNotFoundException or intermittent runtime errors. |
| Rule Resolution Index | Indexes like pr_index_class and pr_index_property are not updated, causing incorrect rule resolution behavior. |
Rules that should be inherited or overridden fail to resolve correctly. |
| Dependency Records | Records in tables that track rule dependencies remain, pointing to the deleted class. | Application packaging, import/export, and deployment pipelines fail with "Invalid Reference" errors. |
| Data Instances | If the class was mapped to a dedicated table, the table structure remains, but the Pega metadata to access it is gone. | Data becomes inaccessible and cannot be properly purged or migrated. |
2. Dependency Breakage and Orphaned Rules
Rules in Pega are tightly coupled to the class defined in the Applies To field. Deleting a class without a controlled process leaves these rules orphaned. When the system attempts to resolve or execute a rule that depends on the deleted class, it results in immediate runtime errors.
3. Impact on Pipelines and Deployments
The Pega deployment manager and underlying product rule generation rely on the integrity of the rule base. Invalid references to a non-existent class will disrupt application promotion, blocking critical delivery processes and increasing rework for development and DevOps teams.
Best Practices for Deactivating or Removing Classes
The only supported and safe way to manage the lifecycle of a class is by leveraging Pega’s built-in refactoring and deletion tools, which ensure that all related metadata, caches, and dependencies are handled transactionally.
1. Use Native Refactoring Tools for Class Movement
If the goal is to move rules from an old class to a new one, the refactoring tool is the correct approach. This tool automatically updates all references and dependencies.
Action: Use the Move a Class wizard.
Navigation: In Dev Studio, find the class in the App Explorer, right-click on it, and select Refactor → Move.
Benefit: This process ensures that all associated rules are moved correctly, references are updated, and system integrity is maintained across all layers.
2. Use the Delete a Class Wizard for Final Removal
If a class is truly obsolete and has no remaining instances or dependencies, use the dedicated wizard.
Action: Use the Delete a Class wizard.
Navigation: Configure → System → Refactor → Classes → Delete
Prerequisite: The system will prevent deletion if any rules still reference the class. You must first use the Move a Class wizard or manually delete/move all dependent rules.
3. Deactivate Classes by Marking as Abstract
If a concrete class is no longer used for new case creation or instantiation, but its rules are still needed for historical data or inheritance, the best practice is to deactivate it gracefully.
Action: Set the class as Abstract.
How: Open the Class rule form and change the Class Type to Abstract.
Benefit: This preserves compatibility for existing data and inheritance while preventing new instances from being created, effectively deprecating the class without breaking the application.
4. Plan Removal with Prior Analysis and Documentation
Never remove a class without a thorough impact assessment.
|
Step |
Tool/Action |
Purpose |
|---|---|---|
| 1. Identify Dependencies | Find Rules (Search) | Search for all rules where the class is used in the Applies To field, or referenced in properties, activities, or data transforms. |
| 2. Check Data Instances | Data-Admin-DB-Table | Check the associated database table to confirm if any data instances (records) exist. If they do, a data migration or archival strategy is required. |
| 3. Validate | Unit Testing/Regression | After refactoring or deletion, run unit tests and regression suites to ensure no unexpected side effects have occurred. |
Conclusion
Direct database manipulation may seem like a quick fix, but it introduces significant, long-term risks to application stability, automation, and Pega Cloud compliance. By leveraging Pega’s built-in tools—the Refactor wizards, the Abstract class setting, and thorough Find Rules analysis—you ensure a robust, maintainable, and fully supported application lifecycle. The minor time saved by a direct database action is never worth the cost of a corrupted environment or a failed production deployment.
References
1- Pega Community. Direct Database Deletions Are Not Recommended for Purging Case Data in Pega. https://support.pega.com/question/direct-database-deletions-are-not-recommended-purging-case-data-pega
2 - Pega Documentation. About the Delete a Class wizard. https://docs.pega.com/bundle/platform/page/platform/app-dev/about-delete-class-wizard.html
3 - Pega Documentation. System > Refactor menu items. https://docs.pega.com/bundle/common-data-model-88/page/common/platform/tools/landing-pages/system-menu-items/system-refactor-menu-items-conref.html