0

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:

  1. Create DevHub Org
  2. Create named credentials in DevHub Org: dev_named and dev_external
  3. Create another DevHub Org for namespace(Namespace Org): ns
  4. Link Dev Hub Org with Namespace Org
  5. Salesforce CLI login to devhub org (all steps in sf cli use devhub org)
  6. Salesforce CLI create project
  7. Salesforce CLI create package
  8. Add metadata to package: 'callout:dev_named'
  9. Package named credential: sf project retrieve -m NamedCredential --target-org devhuborg
  10. 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

  1. Setup
  2. Packaging: Includes package version creation
  3. Usage

What am I missing and what step needs correction, either the setup, the packaging or the usage?

1 Answer 1

0

The thing that was missing was to also package external credentials, once I was able to get that, package creation went smoothly

sf project retrieve -m ExternalCredential --target-org devhuborg

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .