Objective: Create Salesforce Apex package to be distributed, as an integration with a third party service
Development Details: API v61 (Summer 24), SF CLI
Development Steps: Following the workflow Workflow for Second-Generation Managed Packages
Summarizing the steps:
- Create DevHub Org
- Create named credentials in DevHub Org: dev_named and dev_external
- Create another DevHub Org for namespace(Namespace Org): ns
- Link Dev Hub Org with Namespace Org
- Salesforce CLI login to devhub org (all steps in sf cli use devhub org)
- Salesforce CLI create project
- Salesforce CLI create package
- Add metadata to package: 'callout:dev_named'
- Package named credential: sf project retrieve -m NamedCredential --target-org devhuborg
- Salesforce CLI create package version
Step 10 Throws error:
Error (MultipleErrorsError): Multiple errors occurred:
(1) dev_named: The ns__dev_external External Credential doesn't exist.
Noticing the associated namespace I created the same pair of credentials(named, external) in namespace account
Rerun package version creation command: No errors
Go to devhub org to test the callout in dev console: with 'callout:dev_named'
System.CalloutException: The callout couldn't access the endpoint. You might not have the required permissions, or the named credential "dev_named" might not exist.
The three conceptual steps involved in the flow for named credentials are
- Setup
- Packaging: Includes package version creation
- Usage
What am I missing and what step needs correction, either the setup, the packaging or the usage?