function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
gaurav arora 33gaurav arora 33 

Lookup filter getting reset if i use Matadata API for setting the history tracking for lookup field

I am using the Below code to update the history tracking of lookup field to true
MetadataService.MetadataPort service = new MetadataService.MetadataPort();
        service.SessionHeader = new MetadataService.SessionHeader_element();
        service.SessionHeader.sessionId = UserInfo.getSessionId();
        List<MetadataService.CustomField> cfList = new List<MetadataService.CustomField>();
                MetadataService.CustomField customField = new MetadataService.CustomField();
                customField.type_x = 'Lookup';
                customField.fullName = 'Case_Contact__c.Account__c';
                customField.label = 'Account';
                customField.relationshipLabel = 'Case_Contacts';
                customField.relationshipName = 'Case_Contacts';
                customField.referenceTo = 'Account';
                customField.trackHistory = true;
                cfList.add(customField);
                List<MetadataService.SaveResult> results = service.updateMetadata(cfList);

The code works fine. but the problem is if that lookup field has any lookup filter then that would get  deleted.
is there any way to dynamically update the history tracking of lookup field and keeping the lokkup filters intact.