I am getting the following error when I try to merge 2 territories "Cannot proceed. There are records with missing territories. Please call support.".
I have checked all the tables that there are no missing territories but still the message appears.
You are going to have to check whether there are any records with a mismatched territory.
select * from company where Comp_SecTerr in (select terr_territoryid from Territories);
select * from company where Comp_SecTerr not in (select terr_territoryid from Territories);
You will have to check every entity that has a territory field within it.
Simple way to get them all is to clear the SQL log and run the merge. You'll be able to recover the entity list from the select statements recorded. Run each one looking for a blank(NULL) _secterr field.
Ran the scripts and there are no mismatched territories.
Ok, that is clear now. Thank your for your answer.
Search in CRM logs folder where “ewareterritoryerrors” log file will be generated. If you check that file you can find which records are causing issues. In my case, there are opportunities with territory id that does not exists in the Territories table.