I am trying to create a 2GP that includes an Aura component, which shows a canvas app using
I have tested this Aura component by creating it in the developer console. I did this in the organisation where I have a connected app, which is referenced by its developer name. This approach works in the 1GP.
However, I am running into trouble while trying to achieve the same result in a 2GP. I have created a scratch org from my PBO (also my Dev Hub). Then I created a managed package in this scratch org. This all according to this workflow. The project has roughly the following structure:
config | project-scratch-def.json force-app/main/default | aura | CanvasApp | App.cmp | App.design | App.svg | AppController.js | staticresources | canvasStatic.js | canvasStatic.resource-meta.xml sfdx-project.json
App.cmpfile references the Connected App like this:
<force:canvasApp applicationName="Some Name" developerName="<namespace>__<developername>" />
namespaceis the namespace of the previously mentioned 1G package, and the developer name is the name of the Connected App in that package. The namespace of the 1G package is linked to my PBO (Dev Hub), thus the scratch org has the same namespace.
When I create a version for this package, it installs successfully, but when I load the page it reports this message:
Your browsing session has ended or is invalid. Please re-login to Salesforce.com again.
I have tried generating a password for the user account as suggested here, but that did not help. I found this article from SFDX Developer Guides, but I do not understand steps 4 and 6.
Following these instructions actually caused different problems. I added the .xml file as suggested, after which creating the package version would give the following error:
: Installing an app (App Name) that has been deleted.
I also could not install the 1GP package into the scratch org, as they have the same namespace:
- Package(Package ID) Package and subscriber org namespace collision, Details: The installing package namespace and org namespace cannot be the same.
Can anybody tell me how to show a connected app using
force:canvasAppin a 2GP?
You can’t have a 1GP and 2GP by the same namespace in the same org, which explains your last problem.
The directions you linked to presume that the Connected App is in a 1GP, that the 1GP has been previously uploaded in a Released state, and you’re trying to create a 2GP.
Given the above, your source directory is missing the
/connectedApps/<namespace>__<developerName>.connectedApp-meta.xml file, which you need in order to use the Connected App.
The source for the file can be retrieved from the original 1GP packaging org (not the PBO/Dev Hub). The 1GP does not need to be installed to use the Connected App.
You can probably just fix this with the following command:
sfdx force:source:retrieve -m ConnectedApp -u packaging-org
This will give you the correct file you need to complete this setup.