6

Trying to push the source code to a scratch org I get the following error:

The entity: Opportunity does not have history tracking enabled (998:13)

But there is no option to specify on the scratch org definition file to enable the field history on opportunities. The only available option is to turn the history on for contracts.

Is there a workaround for this?

1 Answer 1

8

This issue is now properly addressed in Salesforce DX. You need to set enableAccountHistoryTracking to true, as outlined in the Scratch Org Settings documentation:

{
  "settings": {
   "accountSettings": {
     "enableAccountHistoryTracking": true
    }
  }
}

I've logged that bug with the DX team. The solution (for now) is to have an src directory in mdapi format, deploy the "history tracking" flag on the CustomObject first, and then deploy the fields afterwards.

sfdx force:mdapi:deploy -d src -w 10
sfdx force:source:push

Your src folder would be a traditional package:

src/package.xml

<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <members>Opportunity</members>
        <name>CustomObject</name>
    </types>
    <version>42.0</version>
</Package>

src/objects/Opportunity.object

<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
    <enableHistory>true</enableHistory>
</CustomObject>

Most of the fields are not necessary for standard objects, but be aware you have to specify things like label, fullName, pluralLabel, sharingModel, etc for custom objects.

7
  • Hey, do you have, perhaps, an issue number or link for this bug? It is something I'd like too to keep track of. Jun 29, 2018 at 20:01
  • 1
    @RenatoOliveira I spoke with Wade about it, he said he'd look in to it, but I don't have a number off the top of my head. It may be related to this issue, but the description doesn't match the current problem. I'll ask Wade if there was a Known Issue for this.
    – sfdcfox
    Jun 29, 2018 at 20:05
  • 1
    @RenatoOliveira Oh, glad I could help, then. That was one of our showstoppers until I figured out this handy workaround (we since ran in to other issues, but at least I fixed this).
    – sfdcfox
    Jun 29, 2018 at 20:19
  • 1
    @TemporaryFix Thanks, I've updated the answer to reflect this. I knew it, but as I have about 10k answers, it's hard to keep track of everything that needs updating.
    – sfdcfox
    May 20, 2021 at 23:40
  • 1
    @sfdcfox the community appreciates all that you do! May 20, 2021 at 23:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.