0

I have a managed 2GP package. It has custom objects. The whole project is in SFDX format and stays in a single folder force-app/main/default. when running the tests on the Dev Hub - all works well, but when I try to create a version I get an error when running the tests.

What are the rules to succeed with the package version creation? What do I need to have in the sfdx-project.json & build-scratch-org.json file so that when I try to create a version for my managed 2GP package that has custom objects and fields? And sorry for the dummy request, but please include what is the command to use that build-scratch-org.json file in the version creation process.

There are similar questions, but they refer to non-build org scratch orgs. Let me know if I'm wrong, please.

Let's say I have a CustomObject__c in my Dev Hub org. How do I transfer it to the build scratch org with configuration? I have already read the article series in ktema, but it is still not clear to me how to do it?

Here is the complete message:

  message: System.QueryException: No such column 'External_Field_Name__c' on entity 'Mapping__c'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.

Again, object and field are in the same folder as the test files - in the managed package in sfdx-project.json.

Update 1

I see the same errors during tests when I try to deploy with tests the project to one of my older Dev Hubs. ( I think that it could be something with the API versions between the 2 Dev Hubs).

Update 2

I found out that my real problem was that I have added permissions directly to the System Administrator profile for the custom objects and fields so in the other Dev Org I didn't have those and I was able to reproduce the issue. I've updated my tests to run with an User with the required permission sets.

1 Answer 1

1

message: System.QueryException: No such column 'External_Field_Name__c' on entity 'Mapping__c'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.

This message strongly suggests to me that your code is using a non-packaged field while testing. So two things to bear in mind here:

  1. Your code must use dynamic references (Database.query()) to this field, because otherwise your code will not deploy if the field is not present.
  2. You must make use of the unpackagedMetadata feature (my discussion of this feature) of 2GP packaging to provide that field for use during testing.

I see the same errors during tests when I try to deploy with tests the project to one of my older Dev Hubs. ( I think that it could be something with the API versions between the 2 Dev Hubs).

Remember that your 2GPs are not deployed to the Dev Hub. The Dev Hub creates a build scratch org (on the same API version as the Dev Hub by default). Note that it is possible to have Dev Hubs on different API versions, but it's very unlikely for it to produce a custom field-related error like this.

3
  • These are all packaged fields in my case. I found out that my real problem was that I have added permissions directly to the System Administrator profile for the custom objects and fields so in the other Dev Org I didn't have those and I was able to reproduce the issue. I've updated my tests to run with an User with the required permission sets. Thank you for your time. Could you please see if you can update your answer according to this new informaiton. Sep 29, 2023 at 13:42
  • I don't really understand how what you describe created, or solved, this problem
    – David Reed
    Sep 30, 2023 at 18:49
  • Well, I only had the Object permissions in my packaging DevOrg. They were never copied to the build scratch Orgs. I found the root cause by trying to deploy the same code with tests and code coverage on my other Dev Org and getting the same errors. Then decided to roll back code by using the divide and conquer strategy to find what broke tests. in one of the commits for the CRUD violations I have added a 'WITH SECURITY_ENFORCED' but having the credentials on the SysAdmin assigned in my publishing didn't broke the tests. Hope that clarifies the fog from my last comment. Oct 1, 2023 at 12:55

You must log in to answer this question.

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