You need to sign in to do that
Don't have an account?
Trailhead Account Geolocation Project error
I am on the last step of the Trailhead Account Geolocation project and I get the following error:

Here is the code from the AccountMapController-- What did I do wrong?
({
jsLoaded: function(component, event, helper) {
setTimeout(function() {
var map = L.map('map', {zoomControl: false})
.setView([37.784173, -122.401557], 14);
L.tileLayer(
'https://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/{z}/{y}/{x}',
{
attribution: 'Tiles © Esri'
}).addTo(map);
component.set("v.map", map);
});
},
accountsLoaded: function(component, event, helper) {
// Add markers
var map = component.get('v.map');
var accounts = event.getParam('accounts');
for (var i=0; i<accounts.length; i++) {
var account = accounts[i];
var latLng = [account.Location__Latitude__s, account.Location__Longitude__s];
L.marker(latLng, {account: account}).addTo(map).on('click', function(event) {
helper.navigateToDetailsView(event.target.options.account.Id);
});
accountSelected: function(component, event, helper) {
// Center the map on the account selected in the list
var map = component.get('v.map');
var account = event.getParam("account");
map.panTo([account.Location__Latitude__s, account.Location__Longitude__s]);
}
})
Here is the code from the AccountMapController-- What did I do wrong?
({
jsLoaded: function(component, event, helper) {
setTimeout(function() {
var map = L.map('map', {zoomControl: false})
.setView([37.784173, -122.401557], 14);
L.tileLayer(
'https://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/{z}/{y}/{x}',
{
attribution: 'Tiles © Esri'
}).addTo(map);
component.set("v.map", map);
});
},
accountsLoaded: function(component, event, helper) {
// Add markers
var map = component.get('v.map');
var accounts = event.getParam('accounts');
for (var i=0; i<accounts.length; i++) {
var account = accounts[i];
var latLng = [account.Location__Latitude__s, account.Location__Longitude__s];
L.marker(latLng, {account: account}).addTo(map).on('click', function(event) {
helper.navigateToDetailsView(event.target.options.account.Id);
});
accountSelected: function(component, event, helper) {
// Center the map on the account selected in the list
var map = component.get('v.map');
var account = event.getParam("account");
map.panTo([account.Location__Latitude__s, account.Location__Longitude__s]);
}
})
Jeff Douglas
Trailhead Developer Advocate
All Answers
Jeff Douglas
Trailhead Developer Advocate
I drop in and it's already solved!
Amy, shouldn't it be Jeff's answer as the Best Answer ;)
"AccountList's JS controller does not get a reference to the 'AccountsLoaded' event "
my AccountListController.js looks like this
"AccountList's JS controller does not get a reference to the 'AccountsLoaded' event"
I am using the code copied from the trailhead "Build an Account Geolocation App - Using Events to Add Markers to the Map". My AccountsListController.js is as follows (exactly copied from the trailhead document)
Any ideas on what i am doing wrong?
L.marker(latLng, {account: account}).addTo(map).on('click', function(event) {
helper.navigateToDetailsView(event.target.options.account.Id);
and the helper function 'navigateToDetailsView' - in the AccountMap component:
({
navigateToDetailsView : function(accountId) {
var event = $A.get("e.force:navigateToSObject");
event.setParams({
"recordId": accountId
});
event.fire();
}
})
Has anyone else seen that behaviour?
Facing the same issue ..Please share if you found any resolution
Regards
Siva
It seems var SObjEvent = $A.get("e.force:navigateToSObject");
is returning an undefined event object.
I even restructured the call to navigateToDetailsView slightly:
//helper.navigateToDetailsView(event.target.options.account.Id);
helper.navigateToDetailsView(account);
I get a valid account id but not event.
navigateToDetailsView : function(account) {
console.log("accountID="+account.Id);
var SObjEvent = $A.get("e.force:navigateToSObject");
console.log("event="+SObjEvent);
SObjEvent.setParams({
"recordId": account.Id
});
SObjEvent.fire();
}
Anyone solved this?
[https://salesforce.stackexchange.com/questions/86463/forcenavigatetosobject-call-not-working/185521#185521]
so I added a dependency tag
<aura:dependency resource="markup://force:navigateToSObject" type="EVENT"/> to the component
and got a valid event although nothing happens when you click.
I then added a few more implements to the AccountLocator component
<aura:component implements="force:appHostable,force:lightningQuickActionWithoutHeader,force:hasRecordId,force:appHostable,flexipage:availableForAllPageTypes">
and used the App Builder and it worked.
So it works from an app and on my mobile but not from a web page
....lightning.force.com/c/AccountLocatorApp.app
Something to do with it relying on \one\one.app
I was getting the following error:
Uncaught TypeError: Cannot read property 'setParams' of undefined
throws at https://curious-raccoon-356623-dev-ed.lightning.force.com/c/components/c/AccountMap.js:40:15
Per your advice, I updated AccountLocator.cmp to the following: After doing that, I created a Lightning App Page, dragged the new custom component AccountLocator onto the page, activated the page and added it to an app. After doing all of that, I was able to go to navigate to my new Lightning App Page and click on a pin to open an account record.
I wonder if the explanation Nayana K gave as the "Best Answer" for a different question (https://developer.salesforce.com/forums/?id=9060G000000BhBxQAK) also applies here. She said:
When you try to launch the component via app [...], standard events ([...] navigateToSobject, etc) will be undefined. [...] Therefore launch your [component] in LEX via app builder or lightning quickaction or drag to detail page to check how it works.