I'm working towards moving an existing managed package over to the SFDX CLI metadata format.
Part of the application is a Connected App which forms a core part of a SSO process to an external system via Canvas. So I can't really leave it out of the scratch orgs without taking out other large sections of functionality.
I've found in the past that it isn't possible to include the oauthConfig > consumerKey in the SFDX CLI metadata as that key is unique to the org it was generated in.
After excluding the consumer key from the .connectedApp-meta.xml file I can successfully push the source to a new scratch org.
However, now when I try an push an unrelated change to a Visualforce page to the scratch org I'm getting an "invalid cross reference id" error on the connectedApp. I'm not sure why the CLI is trying to push the connected app again. I haven't made any changes to it. Maybe it has detected the new consumer key that was generated on first push?
I did find a similar question with relation to profiles - Salesforce DX: Pushing profiles gives 'invalid cross reference id'. The suggestion there was to make an arbitrary change to the metadata in Salesforce and then pull it down again.
Trying that, I get the following error:
A general data error occurred with your entries
Any ideas on how to get the connected app into the Scratch org and then being able to work with the org afterwards?
For a Second-Generation managed package there appears to be a special ceremony to go through that results in referencing the Connected App by the namespace (db_0110_ns4) and the connected app name (A_Connected_App). E.g.
<ConnectedApp xmlns="http://soap.sforce.com/2006/04/metadata"> <developerName>db_0110_ns4__A_Connected_App</developerName> <label>A Connected App</label> <version>1.0</version> </ConnectedApp>
I attempted this with my first generation package, but the CLI push came back with the error:
Contact email needs to be in a valid email format
Which suggests it was still looking for the
<contactEmail> element in the metadata file rather than referencing the connected app in the existing package version.