When managing inter-package dependencies during migration from first-generation (1GP) to second-generation packaging (2GP), consider these key aspects:
**Dependency Management During Migration:**
- Design the app and interfaces between packages carefully to avoid breaking dependencies
- Ensure that if an extension package calls an Apex class in the base package, the Apex class is set to global
- Plan for the entire application lifecycle to ensure updates to the base package do not disrupt dependent packages
- If migrating from custom objects to protected custom metadata, thoroughly test the migration process and address any errors encountered
**2GP Migration Considerations:**
- **Namespace Sharing**: 2GP allows namespace sharing across packages, simplifying dependency management and improving modularity
- **Versioning and Dependencies**: Specify the ancestor package version when creating a new package version in 2GP and clearly define and ensure compatibility of dependencies
- **Security Review**: If your 1GP package has passed a security review, confirm whether the 2GP package inherits this readiness or requires a new review
- **Metadata Management**: Adapt metadata components to align with 2GP requirements, ensuring proper configuration of Apex classes, custom objects, and other elements
- **Environment Hub**: Use the Environment Hub to manage orgs effectively during migration, streamlining development, testing, and deployment
**Security Considerations for 2GP Migration:**
- **Namespace Accessibility**: Use the @namespaceAccessible annotation for classes shared across sub-packages within the same namespace - treat these classes as global but ensure controlled access
- **Data Sanitization**: Perform sanitization close to the sink to mitigate security risks effectively
- **Individual Security Reviews**: Each sub-package tied to the parent package must undergo an individual security review to ensure compliance and security
- **Key Management**: For public/private key pairs, ensure each subscriber organization has a unique key pair to maintain security
- **Lightning Message Service (LMS)**: If using LMS channels, ensure they are private to the package and avoid exposing publish/handle message methods in components
**Additional Considerations:**
- Use dynamic Apex to support multiple editions and ensure compatibility with available features
- Thoroughly test the migrated package and its dependencies to ensure functionality and performance, especially scenarios involving dependency interactions
- Update team training and documentation to reflect changes in packaging and dependency management
- For packages with dependencies, you can submit up to four packages (one base and three extension packages) with the same namespace in a single security review submission
If you encounter specific challenges during migration, consider raising a case with Salesforce for additional guidance.