How to Fix KML files not loading in Salesforce Maps

When loading a KML file into Salesforce Maps you might get an “Unable to retrieve or parse the KML document” Error. Here’s why and how to fix KML files.

Reasons for “Unable to retrieve or parse the KML document” Error

  • The KML File is not properly formatted for Salesforce maps
  • The File is too big and will need to be broken down into smaller subsets to fix KML file

See the sections below to see the problem and the possible solutions to fix the KML files.

KML file is not properly formatted for Salesforce Maps

It is a known issue and it might be due to:

  • File is in other related formats such as KMZ, which is a more compressed version of KML. You’ll have to convert it to KML (see section below)
  • The file has the XSI attribute that makes it unreadable in Salesforce maps. You’ll have to remove it using a text editor such as Sublime or Notepad++ in order to fix kml file (see section below)

Convert the file to KML

While it’s possible to convert the KMZ file to KML using web pages and online tools, it’s a lot better to do it from Google Earth.

  1. Open the KMZ file with Google Earth (web) or Google Earth Pro (desktop). If the file is too big, you’ll have to open it on Google Earth Pro. Download and install if you haven’t already.
  2. Right-click on the KMZ under Temporary Places in the left side bar, click on Save Place As…
google earth save place as to fix kml file
  1. Choose a new name and make sure to choose KML format from the dropdown menu
  2. Select a folder and click Save

Remove the XSI attribute to fix KML file

It’s worth noting that if the file was just saved/converted from Google Earth, you won’t need this step. This step is necessary mostly for older KML files or to fix KML files that came from other software other than Google Earth.

  1. Open the KML file with a text editor like Sublime or Notepad++
  2. In the first few lines of code, find the xsi: attribute, select it all the way until the closing > and delete it.
fix kml file removing xsi attribute

It should look like this afterwards:

fix kml file  xsi attribute
  1. Save the edited file and Load it into Salesforce Maps to test if this fixes the KML file

KML File is too big for Salesforce Maps to read or parse

This limitation is not necessarily a number of placemarks but from what I tested it has more to do with the size of the KML file: 5.7mb which might be roughly 1500-2000 placemarks depending on how many points and how many characters each placemark has.

The solution is to break down the file into smaller subsets. See sections below for options.

Break the KML file using a Text Editor

The KML file is basically a kind of XML file, so when you open it on a text editor like Sublime or Notepad++ it is mostly human-readable. The first few lines have information about the file format and the polygons colors, which can be useful if you want to change the color.

Then, each placemark opens with placemark and it’s ID: <Placemark id="ID_00000"> Then, it contains all the information about each point as coordinates and description. Then, it closes the placemark with this closing tag: </Placemark>

fix kml file by breaking it in text editor

Now, all you have to do is break down the file in chunks of 1500 to 2000 placemarks, as long as you keep the file size below 5.7mb.

I recommend creating copies of the original file, cutting or copying the 1800-2000 placemarks to that other file and saving it. Don’t forget to include the starting lines and the last 3 lines (see image above) that have the closing tags.

     </Folder>
</Document
</kml>

Save subsets of KML files using Google Earth Pro

Another option is to break down the KML file from Google Earth Pro and saving subsets of data visually. This option is more intuitive and doesn’t require dealing with code at all. However, it might be a little more tedious and time consuming, specially if the file is really big (300mb+) and/or you don’t have enough processing power in your machine.

Although you could open the file in Google Earth (web), that only works for smaller files. For bigger files, it’s absolutely recommended you use Google Earth Pro (desktop) software. The instructions below are written for Google Earth Pro and they may vary slightly for Google Earth (web).

  1. Open the KML file
  2. Right-click and choose Save to My Places on all the shapes you’d like to be part of the subset. They’ll start piling up on the left sidebar under My Places
fix kml file by creating a subset in google earth pro

Whenever a shape has already been added, it will no longer show the Save to My Places option, so you’ll know which ones you’ve added and which ones not. this is great for the shapes and placemarks that have no name and can only be picked out visually on the map.

fix kml file by creating a subset in google earth pro

Another recommendation is to use the time machine setting and set it to the oldest map, which should have the worst resolution, so that you can focus on the shapes without the map satellite image being intrusive.

fix kml file by creating a subset in google earth pro

If the placemarks or shapes have names that you can easily identify from the left sidebar, then you can easily Shift+Click select them and then copy them to My Places.

  1. Create a folder inside my places, by right-clicking on My Places and selecting Add and then choose Folder
google earth pro my places add a new folder
  1. Name your folder in the new pop up window and click OK
  2. Click on the first Placemark or shape from your collected subset in My Places and then Shift+Click the last one to select them. Drag and drop them inside the folder you’ve just created
  3. Right-click on the folder and choose Save Place As…
  4. Choose KML format, name your file and choose a location.
  5. Click Save

Repeat these steps to save every subset and then Load the KML files into Salesforce Maps to test them out.

Was this article helpful?
YesNo