managed-package-development

Use when building or maintaining Salesforce first-generation managed packages (1GP) for ISV distribution — covers namespace registration, packaging org structure, PostInstall/UninstallHandler Apex interface, push upgrades, Flow version management, and subscriber org considerations. NOT for second-generation managed packages (2GP), unlocked packages, or AppExchange listing setup.

Best use case

managed-package-development is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Use when building or maintaining Salesforce first-generation managed packages (1GP) for ISV distribution — covers namespace registration, packaging org structure, PostInstall/UninstallHandler Apex interface, push upgrades, Flow version management, and subscriber org considerations. NOT for second-generation managed packages (2GP), unlocked packages, or AppExchange listing setup.

Teams using managed-package-development should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/managed-package-development/SKILL.md --create-dirs "https://raw.githubusercontent.com/PranavNagrecha/AwesomeSalesforceSkills/main/skills/devops/managed-package-development/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/managed-package-development/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How managed-package-development Compares

Feature / Agentmanaged-package-developmentStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Use when building or maintaining Salesforce first-generation managed packages (1GP) for ISV distribution — covers namespace registration, packaging org structure, PostInstall/UninstallHandler Apex interface, push upgrades, Flow version management, and subscriber org considerations. NOT for second-generation managed packages (2GP), unlocked packages, or AppExchange listing setup.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Managed Package Development

This skill activates when a practitioner needs to build or maintain a Salesforce first-generation managed package (1GP) for ISV AppExchange distribution. It covers the packaging org structure, namespace registration, the PostInstall Apex interface, the critical constraint that Flow versions in released packages cannot be deleted, and the differences between the packaging org and patch org model.

---

## Before Starting

Gather this context before working on anything in this domain:

- 1GP managed packages require a dedicated packaging org — a Developer Edition org where the package is authored and uploaded. This is a single org-per-package constraint (not per-namespace).
- The namespace is registered in a separate Developer Edition org and then linked to the packaging org Dev Hub. The namespace choice is permanent — it cannot be changed or reused after registration.
- Package upload (creating a new version) is done via Setup UI or Tooling API in the packaging org — not via `sf package version create` CLI, which is a 2GP command.
- Flows uploaded to a released or beta 1GP managed package **cannot be deleted** from the packaging org — only individual Flow versions can be removed, and only if a later version exists.
- The PostInstall/UninstallHandler Apex class name is locked after the first upload to a released managed package — the class body can change but the name cannot.

---

## Core Concepts

### Packaging Org and Namespace Structure

1GP managed packages use a dedicated packaging org model:

- **Namespace Dev Edition Org** — A Developer Edition org where the namespace identifier is registered (Setup > Company Profile > Namespace Prefix). This org becomes the namespace authority.
- **Packaging Org** — A separate Developer Edition org where all package components live. The packaging org is linked to the namespace by importing the registered namespace.
- **Patch Org** — For each released package version, a patch org can be created to develop patch releases (bug fixes only, no new features). One patch org per major.minor version.

There is no concept of "Dev Hub" or "scratch org" in 1GP — all development happens directly in the packaging org.

### PostInstall and UninstallHandler Interface

1GP managed packages can execute custom Apex logic when the package is installed, upgraded, or uninstalled in a subscriber org. This is implemented via the `InstallHandler` Apex interface:

```apex
global class MyPostInstall implements InstallHandler {
    global void onInstall(InstallContext context) {
        if (context.previousVersion() == null) {
            // Fresh install logic
        } else {
            // Upgrade logic — use context.previousVersion() to branch
        }
    }
}
```

The class implementing `InstallHandler` is registered in the Package Settings and its **API name is locked after the first upload to a released package**. Only the class body (logic) can be changed in subsequent versions.

For uninstall, implement `UninstallHandler`:
```apex
global class MyUninstall implements UninstallHandler {
    global void onUninstall(UninstallContext context) {
        // Cleanup logic
    }
}
```

### Flow Version Management in 1GP

Flows in a 1GP managed package have a critical constraint: once a Flow is uploaded to a released or beta package, **the Flow cannot be deleted from the packaging org**. You can:
- Deactivate a Flow version
- Remove individual older Flow versions (if a newer version exists)
- Create new Flow versions

But you cannot delete the Flow itself from the packaging org after it has been included in a released package. This creates a permanent registry of all Flows ever shipped in the package.

**Implication:** Be deliberate about which Flows are included in a managed package. Test Flows thoroughly before including them in a managed release.

---

## Common Patterns

### Pattern 1: PostInstall Script for Configuration Seeding

**When to use:** The package requires default Custom Metadata records, Permission Set assignments, or Named Credentials to be created in the subscriber org at install time.

**How it works:**
1. Implement `InstallHandler` in a global Apex class
2. In `onInstall()`, check `context.previousVersion()` to distinguish fresh install from upgrade
3. For fresh install: insert default data records, assign permission sets to installing user
4. For upgrades: use version comparison to apply migration logic only for specific upgrade paths
5. Register the class name in Package Settings > Post Install Class before the first released upload

**Why not use Setup steps in subscriber org:** PostInstall scripts run automatically at install time, reducing subscriber configuration burden. For ISV packages, automated post-install configuration is a quality-of-life feature that reduces support requests.

### Pattern 2: Push Upgrade for Bug Fixes

**When to use:** A critical bug in a released package version needs to be fixed in all subscriber orgs without requiring subscribers to manually install the update.

**How it works:**
1. Create a new package version with the fix in the packaging org
2. Upload the version via Setup > Package Manager > Upload
3. Navigate to Package Details > Push Upgrades and schedule the push
4. Push upgrades are subject to subscriber org governor limits — the PostInstall script runs in the subscriber org and must stay within limits

**Why not wait for subscriber voluntary install:** Push upgrades ensure all subscribers receive critical security or data integrity fixes promptly. Voluntary upgrade adoption rates are often low.

---

## Decision Guidance

| Situation | Recommended Approach | Reason |
|---|---|---|
| New ISV managed package for AppExchange | 1GP packaging org with namespace | AppExchange requires managed package with IP protection |
| New internal modular package, no AppExchange | 2GP unlocked package | 2GP supports CLI-driven workflow and multi-package namespaces |
| Post-install configuration needed | InstallHandler Apex interface | Runs automatically at install/upgrade time in subscriber org |
| Bug fix across all subscribers | Push upgrade from Package Manager | Subscriber voluntary installs have low adoption rates |
| Flow in package needs to be deleted | Not possible after release upload | Can only deactivate/version — plan Flows before releasing |
| Package upload | Setup UI > Package Manager or Tooling API | 2GP CLI (`sf package version create`) does NOT work for 1GP |

---

## Recommended Workflow

1. **Register namespace** — In a dedicated Developer Edition org, register the namespace prefix (Setup > Company Profile > Namespace Prefix). Document the namespace — it is permanent.
2. **Configure packaging org** — Import the namespace into the packaging org by linking it in Setup > Package Manager. Create the package in the packaging org.
3. **Develop in packaging org** — Build all components (Apex, Flows, custom objects, layouts) directly in the packaging org. Test in the packaging org itself or a scratch org linked to it.
4. **Implement PostInstall/UninstallHandler** — Write the InstallHandler Apex class and register it in Package Settings before the first released upload. Confirm the class name — it cannot change after the first released upload.
5. **Test Flows before including in package** — Flows included in a released package cannot be deleted from the packaging org. Test all Flows thoroughly in a separate org before adding them to a managed release.
6. **Upload new package version** — Use Setup > Package Manager > Upload in the packaging org. Set the version number and release type (Beta or Released).
7. **Plan push upgrades** — For Released versions with bug fixes, schedule push upgrades via Package Details > Push Upgrades. Monitor upgrade status across subscriber orgs.

---

## Review Checklist

- [ ] Namespace registered in a dedicated Dev Edition org — name is permanent
- [ ] Packaging org configured with namespace linked
- [ ] PostInstall class name finalized before first released upload
- [ ] Flows tested thoroughly before inclusion in any managed release
- [ ] Package upload via Setup UI or Tooling API — not `sf package version create` CLI
- [ ] PostInstall script tested in sandbox with `Test.testInstall()` Apex testing method
- [ ] Push upgrade plan documented with subscriber org impact analysis

---

## Salesforce-Specific Gotchas

1. **PostInstall class name is locked after first released upload** — The API name of the class implementing InstallHandler is registered in Package Settings. After the first Released package version is uploaded with this class, the name cannot be changed — only the body. Plan the class name before the first release.
2. **Flows in released packages cannot be deleted from the packaging org** — Once a Flow is included in a Released or Beta managed package, it cannot be deleted from the packaging org. Only individual older versions can be removed (if a newer version exists). Be deliberate about which Flows are included in managed releases.
3. **`sf package version create` CLI is a 2GP command, not valid for 1GP** — First-generation managed packages are uploaded via Setup UI (Setup > Package Manager > Upload) or Tooling API. The `sf package version create` command in the Salesforce CLI only works with second-generation (2GP) packages.

---

## Output Artifacts

| Artifact | Description |
|---|---|
| Packaging org setup guide | Namespace registration steps and packaging org configuration |
| PostInstall class implementation | InstallHandler and UninstallHandler Apex with install/upgrade branching |
| Flow management policy | Which Flows are included in managed releases and version management strategy |
| Push upgrade plan | Version selection, subscriber org impact, and rollout schedule |

---

## Related Skills

- `devops/second-generation-managed-packages` — For 2GP managed packages with CLI-driven workflow
- `devops/package-development-strategy` — For selecting the right package type (1GP vs 2GP vs unlocked)
- `devops/cpq-deployment-patterns` — For deploying CPQ configuration alongside managed packages

Related Skills

apex-managed-sharing-patterns

8
from PranavNagrecha/AwesomeSalesforceSkills

Grant row-level access programmatically via __Share records when declarative sharing rules cannot express the policy. NOT for OWD, role hierarchy, or criteria-based sharing rule design.

lwr-site-development

8
from PranavNagrecha/AwesomeSalesforceSkills

Use this skill when building or customizing sites on the Lightning Web Runtime (LWR) in Experience Cloud — including component authoring, custom theming with --dxp hooks, layout components, and publish lifecycle management. Trigger keywords: build LWR site Experience Cloud, Lightning Web Runtime custom theme, LWR component development community, Build Your Own LWR template, Microsite LWR, lightningCommunity__Theme_Layout, --dxp styling hooks. NOT for Aura-based communities (Build Your Own Aura template). NOT for standard Experience Builder drag-and-drop configuration without code.

data-cloud-activation-development

8
from PranavNagrecha/AwesomeSalesforceSkills

Use this skill when building developer-driven Data Cloud activation surfaces: webhook Data Action Targets with HMAC-SHA256 signing, Salesforce Platform Event data actions, Data Cloud-Triggered Flows on DMO insert, or Marketing Cloud journey triggers. Triggers on: webhook data action target, Data Cloud triggered Flow not firing, HMAC secret key for data action, platform event from Data Cloud, DMO insert trigger. NOT for configuring standard admin-level Activation Targets (SFTP, ad platform segment publishing, CRM segment activation) — those require admin configuration skills, not this developer extensibility skill.

unlocked-package-development

8
from PranavNagrecha/AwesomeSalesforceSkills

Use this skill when designing, creating, versioning, or installing unlocked packages: package directory configuration in sfdx-project.json, namespace management, package dependencies, version lifecycle (beta vs. released), ancestor versions, installation keys, and subscriber installation via sf CLI or Package Install UI. NOT for 2GP managed packages (ISV packaging with namespaces, push upgrades, or AppExchange listings), 1GP managed packages, change set deployments, or scratch org setup.

second-generation-managed-packages

8
from PranavNagrecha/AwesomeSalesforceSkills

2GP managed package development: creating managed packages with Dev Hub and Salesforce CLI, semantic versioning, patch versions, namespace linking, ISV AppExchange listing, and subscriber upgrade management. NOT for unlocked packages, unmanaged packages, or 1GP-only workflows.

package-development-strategy

8
from PranavNagrecha/AwesomeSalesforceSkills

Use this skill when deciding between Salesforce package development approaches — unmanaged, unlocked, 1GP managed, or 2GP managed — including namespace selection, ISV distribution requirements, upgrade path design, and AppExchange packaging strategy. Trigger keywords: should I use managed or unlocked package, Salesforce package type selection, 2GP vs 1GP managed package, namespace decision Salesforce, ISV AppExchange packaging, unlocked package strategy. NOT for individual package creation steps, scratch org setup, or day-to-day package version build commands.

multi-package-development

8
from PranavNagrecha/AwesomeSalesforceSkills

Designing, orchestrating, and maintaining multi-package architectures in Salesforce DX: dependency DAG design, layered package decomposition, install ordering, cross-package API contracts, mono-repo vs. multi-repo layout, and CI/CD pipeline sequencing for projects with two or more unlocked or managed packages. NOT for single-package creation or versioning (see unlocked-package-development), 2GP managed-package ISV workflows (see second-generation-managed-packages), or change-set deployments.

metadata-api-and-package-xml

8
from PranavNagrecha/AwesomeSalesforceSkills

Metadata API concepts, package.xml manifest structure, retrieve and deploy workflows, what metadata types can and cannot be retrieved, deployment order dependencies, and destructiveChanges.xml for deletions. NOT for SFDX source-format details or sf CLI command syntax (use sf-cli-and-sfdx-essentials), and NOT for CI/CD pipeline automation (use devops skills).

cti-adapter-development

8
from PranavNagrecha/AwesomeSalesforceSkills

Use when building or debugging a browser-based CTI softphone adapter using the Salesforce Open CTI JavaScript API — covers callcenter.xml definition, Lightning utility item registration, core API methods (enableClickToDial, onClickToDial, screenPop, setSoftphonePanelHeight, saveLog), call logging as Task, and the lightning-click-to-dial LWC component. NOT for Service Cloud Voice Amazon Connect setup, Omni-Channel routing configuration, or CTI adapter AppExchange package selection.

apex-managed-sharing

8
from PranavNagrecha/AwesomeSalesforceSkills

Sharing records programmatically via Apex: Share objects, row cause, sharing recalculation, with/without sharing patterns. NOT for declarative sharing rules (use sharing-and-visibility).

ampscript-development

8
from PranavNagrecha/AwesomeSalesforceSkills

Use this skill when writing, debugging, or reviewing AMPscript in Marketing Cloud email bodies, subject lines, preheaders, SMS, push notifications, or Cloud Pages — including Lookup/LookupRows data retrieval, IF/ELSEIF conditional blocks, FOR loops over rowsets, and inline personalization. NOT for Server-Side JavaScript (SSJS), REST API calls from content, SQL Query Activities, or Journey Builder configuration.

einstein-discovery-development

8
from PranavNagrecha/AwesomeSalesforceSkills

Use this skill when integrating Einstein Discovery predictions into Salesforce apps, automating bulk scoring jobs, deploying stories as prediction definitions, managing models via API, or querying prediction history. Trigger keywords: Einstein Discovery, smartdatadiscovery, predict endpoint, bulk scoring job, model refresh job, prediction definition, story deployment, regression prediction, multiclass prediction, CRM Analytics ML. NOT for CRM Analytics dashboard design, TCRM dataset management, Einstein Prediction Builder binary classification (which requires no CRM Analytics license), or Einstein Next Best Action recommendation strategies.