Loading
Slack製品の問い合わせ先はSalesforce Helpへ統合・変更されます続きを読む

Salesforce Second-Generation Package (2GP) Version Creation Troubleshooting

公開日: Oct 9, 2026
説明

This guide helps you troubleshoot some of the common Second-Generation Package (2GP) version creation issues in Salesforce. It covers package configuration, metadata validation, scratch org feature settings, and package dependency errors, with Salesforce CLI commands and walkthrough videos for each step.

解決策

This article walks through troubleshooting steps for common 2GP (Second-Generation Package) version creation issues in Salesforce, covering package configuration, metadata validation, scratch org feature and setting requirements, and package dependency verification.

Step 1: Package Version Creation Validation

Check Package Configuration

  • Verify the sfdx-project.json package configuration.
  • Ensure the proper package type (Managed or Unlocked).
  • Validate package naming conventions.

Run the Build Process Validation

Run a package version build without code coverage to validate that the required metadata is valid. The first command creates the package version and waits up to 10 minutes. The second command reports the build status.

# Create package version with validation
sf package version create --package <package-alias> --installation-key-bypass --wait 10

# Check build status
sf package version report --package-version-id <version-id>

The following video walks you through package version creation validation.

Step 2: Verifying Metadata

Validate that metadata can be successfully deployed to the build org without errors. Follow these debugging actions:

  1. Deploy to a scratch org: Create a scratch org with a scratch-org-def file containing the required features and settings related to the metadata, and install any dependencies.
    • Test deployment of the entire project or package metadata in the scratch org.
    • Check for any deployment errors or test class failures.
    • Validate the metadata structure.
  2. Check for common issues:
    • Invalid metadata syntax
    • Missing required fields
    • Permission issues
    • Custom object and field conflicts

Run the Metadata Validation Commands

The following commands deploy with validation only, check metadata validity, and deploy to a scratch org for testing.

# Deploy with validation only
sf project deploy start --source-dir force-app --dry-run

# Check metadata validity
sf project deploy validate --source-dir force-app

# Deploy to scratch org for testing
sf project deploy start --source-dir force-app --target-org <scratch-org-alias>

The following video walks you through verifying metadata.

Step 3: Enabling Features and Settings

  1. Review the features and settings in project-scratch-def.json:
    • Check that all required features on which the package metadata depends are enabled (for example, enableEnhancedNotes, enableLiveAgent, enableOmniChannel).
    • Ensure API version compatibility.
    • Make sure to use the right preview flag during release times.
  2. Check for common issues:
    • Missing features and preferences that the metadata depends on
    • Incorrect API version settings
    • Incompatible feature combinations

The following video walks you through enabling features and settings.

Run the Scratch Org Commands

The following commands validate the scratch org definition, display the org features, and create a package version using the scratch org definition file.

# Validate scratch org definition
sf org create scratch --definition-file config/project-scratch-def.json --dry-run

# Check org features
sf org display --target-org <scratch-org-alias>

# Creating a package with scratch org def file
sf package version create --package <package alias/ID> --installation-key-bypass -v <target-org>

Step 4: Verifying Package Dependencies

This step is required only if the package has dependencies. Validate that all package dependencies are correctly defined in the package directory file. Follow these steps:

  1. Review sfdx-project.json:
    • Verify all dependencies required for the package metadata are listed in the dependencies section.
    • Check version numbers (for example, 1.0.0.RELEASED) and package IDs (for example, 04txxx).
    • Ensure the dependency hierarchy is correct.
  2. Check for common issues:
    • Missing package dependencies
    • Incorrect version numbers
    • Circular dependencies
    • Unresolved dependency conflicts

Run the Dependency Validation Commands

The following commands validate the project configuration, show the dependency tree, and resolve dependencies with a validation-only deployment.

# Validate project configuration
sf project validate start

# Check dependency tree
sf project dependency tree

# Resolve dependencies
sf project deploy start --source-dir force-app --dry-run

For links to the scratch org feature list, metadata settings, release selection, and dependency documentation, see Additional Resources.

ナレッジ記事番号

005227981

 
読み込み中
Salesforce Help | Article