You need to sign in to do that
Don't have an account?
Marco8055
TypeError: Action failed: c:AccountMap$controller$onAccountsLoaded [accounts is null] Callback failed: apex://AccountSearchController/ACTION$searchAccounts
https://trailhead.salesforce.com/en/content/learn/projects/develop-account-geolocation-app-with-aura-components/develop-account-geo-app-create-account-map-component
I'm just working on this, and it all looks good until you start typing in the search box.
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 );
}
})
I'm just working on this, and it all looks good until you start typing in the search box.
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 );
}
})
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" );
console.log("Here"+searchTerm.length);
if(searchTerm != null){
console.log(searchTerm.length);
if(searchTerm.length >= 3){
console.log("In:"+searchTerm.length);
//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 );
}
}
}
})
Cheers everyone!