+ Start a Discussion
Alaric WimerAlaric Wimer 

Error when running sfdx force:package:create for an Unlocked Package

I am trying to create a package version of a project. The Test class of this project references some required fields in the particular org I am working in, but those fields are not a part of my actual package. In addition, RecordTypeId field is referenced in some validation rules that are a part of this package. 

 

I am getting the following error when running sfdx force:package:create https://prnt.sc/tumblg  (https://prnt.sc/tumblg)

 

Does anyone know how I can create a package version in a situation like this?

ShirishaShirisha (Salesforce Developers) 
Hi Alaric,

Greetings!

Seems like your OpportunityReportControllerTest is referring to the fields which are not part of the package which is why you might be getting this error.

So,I would suggest you to include those missing fields in your package to fix those errors.

Kindly mark it as best answer if it helps so that it can help others in the future.

Warm Regards,
Shirisha Pathuri
Alaric WimerAlaric Wimer
Thank you Shirisha, the problem is that if I include those fields in my package, and uninstall the package later, then those fields will be deleted. Those fields already exist in the org before the package was created. Is there any way I can reference these fields without having them in my package?