How to enable Account History Tracking in Scratch Org?
Salesforce is taking its sweet time to fix this problem, so I've created scripts to help me prepare for deployment by switching out tags from the fields involved.
This is prep4scratch.sh
, to take out the unwanted tags:
#!/bin/bash
# prep4scratch.sh - Prepare for deployment to scratch org
find . -name \*.field-meta.xml -exec grep -s -l -e '<trackHistory>true</trackHistory>' {} \; | xargs sed -i '' -e 's|<trackHistory>true</trackHistory>|<trackHistory>false</trackHistory><!-- Should be true -->|'
This is prep4prod.sh
, to restore the original tags:
#!/bin/bash
# prep4prod.sh - Prepare for deployment to production or sandbox org
find . -name \*.field-meta.xml -exec grep -s -l -e '<trackHistory>false</trackHistory><!-- Should be true -->' {} \; | xargs sed -i '' -e 's|<trackHistory>false</trackHistory><!-- Should be true -->|<trackHistory>true</trackHistory>|'
Note: sed -i ''
is a macos specific notation, use sed -i
(without the single quotes) on Linux.
Hope this helps!
Salesforce says that they've logged an issue in their system but do not have a fixed timeline as to when it'd be fixed, in the Success Community discussion pointed out by Fabien here: https://success.salesforce.com/0D53A00003BauKc
The current workaround suggested by them plus common sense says:
a) Strip down Enable History Tags from Scratch org metadata and add them when deploying to sandboxes.
b) Enable History tracking manually before pushing the code to the scratch org.