You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
CustomField.trackHistory : disable/enable fields under Field History Tracking using the apex code (Metadata service) is not working correctly. It is showing ambiguous behaviour. This happens for the standard objects that do not have enable history tracking button, but we need to track the fields separately (i.e case,asset).
#276
Issue : Metadata API using apex is not able to disable/enable fields under Field History Tracking using the apex code. It is showing ambiguous behaviour.
Steps to reproduce the issue :
Use the sample apex code in the anonymous window :
List objList = new List{'Case' };
List<MetadataService.Metadata> deployList = new List<MetadataService.Metadata>();
MetadataService.MetadataPort service = DM_SandboxHelper.createService();
List<MetadataService.CustomObject> customLabelMetaList = (List<MetadataService.CustomObject>) service.readMetadata('CustomObject', objList).getRecords();
MetadataService.CustomObject cusObj = customLabelMetaList.get(0);
system.debug('cusObj.enableHistory '+cusObj.enableHistory);
for(MetadataService.CustomField cf :cusObj.fields){
Issue affects only the fields of the standard objects like case and assets etc that does not have a single point of enabling the history tracking ex : "Enable Account History" button on account.
Issue : Metadata API using apex is not able to disable/enable fields under Field History Tracking using the apex code. It is showing ambiguous behaviour.
Steps to reproduce the issue :
Use the sample apex code in the anonymous window :
List objList = new List{'Case' };
List<MetadataService.Metadata> deployList = new List<MetadataService.Metadata>();
MetadataService.MetadataPort service = DM_SandboxHelper.createService();
List<MetadataService.CustomObject> customLabelMetaList = (List<MetadataService.CustomObject>) service.readMetadata('CustomObject', objList).getRecords();
MetadataService.CustomObject cusObj = customLabelMetaList.get(0);
system.debug('cusObj.enableHistory '+cusObj.enableHistory);
for(MetadataService.CustomField cf :cusObj.fields){
if(cf.fullName == 'Description' || cf.fullName == 'BusinessHoursId' || cf.fullName == 'Priority' || cf.fullName == 'Type '){
System.debug('fullName -- '+cf.fullName);
cf.trackHistory = true ;
}
}
deployList.add(cusObj);
List<MetadataService.SaveResult> results = service.updateMetadata(new List<MetadataService.CustomObject>{cusObj});
1] Use this line in code to change the value to true or false.
cf.trackHistory = true ;
2] Here i am trying with the fields : 'Description' , 'BusinessHoursId', 'Priority', 'Type' on case object.
3] Check the field tracking page of the case object :
https://summer21v52-dev-ed.my.salesforce.com/p/setup/layout/LayoutFieldList?type=Case&setupid=CaseFields&retURL=%2Fui%2Fsetup%2FSetup%3Fsetupid%3DCase
4] Turn off all the history tracking of the above fields.
5] Now execute the above code in the anonymous window.
Result : You will see the history tracking is enabled for only fields : Description, Priority but for other fields this is not enabled.
Need to understand why is the behaviour not consistent across the fields.
I have checked the same using the Metadata deployment using the sfdx and the deployment works correctly.
The text was updated successfully, but these errors were encountered: