[SalesForce] How to deploy a Layout with a Related List containing a Geolocation field using ant/the Metadata API

Using ant, when doing a retrieve() of a Layout containing a Related List, containing a Geolocation field (see abridged, sanitised example below), the relatedLists node contains two entries for the Geolocation field – one for the latitude column shown in the interface, and one for the longitude column.

However, both of those entries are simply the custom field reference Item__c.Location__c, rather than (for example) Item__c.Location__Latitude__s and Item__c.Location__Longitude__s as might be expected.

<?xml version="1.0" encoding="UTF-8"?>
<Layout xmlns="http://soap.sforce.com/2006/04/metadata">
    <relatedLists>
        <fields>Item__c.Location__c</fields>
        <fields>Item__c.Location__c</fields>
        <relatedList>Item_Proximity__c.Item__c</relatedList>
    </relatedLists>
</Layout>

Attempting to deploy this to a Salesforce org turns up a rather unhelpful error message:

*********** DEPLOYMENT FAILED ***********
Request ID: 0Af3B000001LGg9SAG

All Component Failures:
1.  layouts/Item__c-Item Layout - Admin.layout -- Error: Field: layoutRow, value:FK_0BC50000000TN3q appears more than once

*********** DEPLOYMENT FAILED ***********

To get to the root of what the message is complaining about, you need to open the layout editor in your browser, inspect the source, and search for the ID appearing in the message (FK_0BC50000000TN3q). This turns up a chunk of JSON like the following, making it clear the issue is the geolocation field supposedly appears more than once in your deployment

{
    "filterColumn": "FK_0BC50000000TN3p",
    "isSortable": true,
    "label": "Item Location: location (Latitude)",
    "type": "N"
},
{
    "filterColumn": "FK_0BC50000000TN3q",
    "isSortable": true,
    "label": "Item Location: location (Longitude)",
    "type": "N"
}

So the obvious solution to me seemed to be to try changing the XML to use the proper references instead, like so

<?xml version="1.0" encoding="UTF-8"?>
<Layout xmlns="http://soap.sforce.com/2006/04/metadata">
    <relatedLists>
        <fields>Item__c.Location__Latitude__s</fields>
        <fields>Item__c.Location__Longitude__s</fields>
        <relatedList>Item_Proximity__c.Item__c</relatedList>
    </relatedLists>
</Layout>

This doesn't work however, producing an Error: Invalid field error when attempting to deploy.

I've tried all the other permutations I could think of to get this deploying, and all of them cause the same error – including:

  • Adding proper lat/long compound field access (as shown above)

        <fields>Item__c.Location__Latitude__s</fields>
        <fields>Item__c.Location__Longitude__s</fields>
    
  • Lowercasing the lat/long words

        <fields>Item__c.Location__latitude__s</fields>
        <fields>Item__c.Location__longitude__s</fields>
    
  • Deploying only one <fields> node, containing a __s reference

        <fields>Item__c.Location__s</fields>
    
  • Deploying only one <fields> node, containing a __c reference

        <fields>Item__c.Location__c</fields>
    
    • This one at least didn't error out on deploy, but it resulted in the layout having only the latitude column, instead of both the lat and long (or a combined column)
  • Switching versions around between 34.0 and 36.0 in all their various combos (doing this for both retrieves and deploys) – none of that made any difference

  • Retrieving using MM in both Tooling and Metadata API modes, retrieving using Force IDE, retrieving using command line ant, etc – no difference to either the retrieved XML or errors on deploying it

  • Probably tried other things too, but fatigue is setting in!

Likely going to open a ticket with Salesforce for this – hopefully this is just an oversight in Geolocation handling, but if anyone has previously encountered this and has a solution, would be much appreciated. If not, I'll post what I hear back from support

Edit: Forgot to add – you can successfully deploy a layout such as the one described here if the target org has EXACTLY the same layout as the one you're trying to deploy. Useless I know, and seems obvious – but if you try to reproduce this issue by simply pulling down the XML for such a layout and then deploying, your deploy will be successful, as it appears that Salesforce compares the XML already in the target org with the XML you're trying to deploy, and if they're identical, Salesforce makes no changes to that layout and your build continues. The issue arises if you either change the layout on the server, or in the XML you are trying to deploy

Best Answer

In case no one else answers, I recommend you create two formulas (e.g. Location_Latitude__c and Location_Longitude__c) and include those in your layout instead. It's an annoying workaround, but hardly the worst out there.