+ Start a Discussion

TypeError: Action failed: c:AccountMap$controller$onAccountsLoaded [accounts is null] Callback failed: apex://AccountSearchController/ACTION$searchAccounts


I'm just working on this, and it all looks good until you start typing in the search box.

When delete the text to add next location
Code for AccountMapController.js
    onAccountsLoaded: function( component, event, helper ) {
        var mapMarkers = [];
        var accounts = event.getParam( 'accounts' );
        for ( var i = 0; i < accounts.length; i++ ) {
            var account = accounts[i];
            var marker = {
                'location': {
                    'Street': account.BillingStreet,
                    'City': account.BillingCity,
                    'PostalCode': account.BillingPostalCode
                'title': account.Name,
                'description': (
                    'Phone: ' + account.Phone +
                    '<br/>' +
                    'Website: ' + account.Website
                'icon': 'standard:location'
            mapMarkers.push( marker );
        component.set( 'v.mapMarkers', mapMarkers );
Daniel PiserchiaDaniel Piserchia
i am running into the same issue today, bummer to see nobody has replied to this. If i find the solution i'll come back and post it. mine works fine on desktop but crashes on mobile. 
Phil SnowballPhil Snowball
Ive got the same issue, ditto as above
Caroline PooleCaroline Poole
I have the same issue! I have yet to find a solution.
Daniel PiserchiaDaniel Piserchia
@phil @caroline

hi everyone! after working with support for weeks i finally got a solution. it doesn't change the fact that the locator itself is kind of a poor tool (doesn't seem to really search by location but rather searches the keyword itself, so for instance if you search chicago it will not pull up nearby accounts in evanston) but it does fix this problem:

Hi Daniel,

Thank you for the time on call.

As discussed that we were able to reproduce the same in the desktop version in our local org.

This is occurring due to the standard behavior of the SOSL query and to avoid this error, we have implemented the below SAMPLE code that seems to work as expected in the browser and mobile. Kindly try the below code at your end and let us know if you face any issue:

Account Search Controller:


onInit: function( component, event, helper ) {
// proactively search on component initialization
var searchTerm = component.get( "v.searchTerm" );
helper.handleSearch( component, searchTerm );

onSearchTermChange: function( component, event, helper ) {
// search anytime the term changes
var searchTerm = component.get( "v.searchTerm" );
if(searchTerm != null){
if(searchTerm.length >= 3){

//var delayMillis = 5000;
// get timeout id of pending search action
//var timeoutId = component.get( "v.searchTimeoutId" );
//clearTimeout( timeoutId );

//timeoutId = setTimeout( $A.getCallback( function() {
        helper.handleSearch( component, searchTerm );
//}), delayMillis );
//component.set( "v.searchTimeoutId", timeoutId );
Daniel PiserchiaDaniel Piserchia
meant to say the search doesn't work by *proximity. it just searches the entire account record for mentions of the location you search. annoying because if you for instance search "seattle" it'll catch records with chatter comments like "had lunch in seattle with Mr smith" even if they are actually based in orlando and have the account location fields populated as such. I was really only looking at this course to try and replicate the funtionality of Salesforce Maps/Map Anything without spending even more $$$ and having my boss crucify me, but it doesn't seem robust enough and I lack the java/apex experience to make it so. i'm working instead on this free app i found on the exchange called Map It 360, haven't had much time to try out the setup but if you're like me and looking for a free alternative to Salesforce Maps, that could be an option.

Cheers everyone!
Caroline PooleCaroline Poole
@daniel I am currently working on a home grown solution to replace MapAnything as well! If I am able to make this or any other system more robust, I will make sure to reach out!