You need to sign in to do that
Don't have an account?
MasahiroY
Accounts plotted on Google Map with Lightning Component
I've successfully plotted the accounts on Google Map with Lightning Component and it works in Sandbox...but don't know how to write a test code for the ApexClass.
I describe the codes below and hope anyone can help with the test code part. Thank you!
Component (MapNearbyAccount.cmp)
I describe the codes below and hope anyone can help with the test code part. Thank you!
Component (MapNearbyAccount.cmp)
<aura:component controller="MapNearbyAccountController" implements="flexipage:availableForAllPageTypes,force:hasRecordId"> <aura:attribute name="mapMarkers" type="Object"/> <aura:attribute name="selectedMarkerValue" type="String" /> <aura:handler name="init" value="{! this }" action="{! c.init }"/> <div class="slds-box slds-theme--default"> <lightning:map mapMarkers="{! v.mapMarkers }" selectedMarkerValue="{!v.selectedMarkerValue}" markersTitle="accounts nearby" listView="auto" showFooter="false" onmarkerselect="{!c.handlerMarkerSelect}" /> </div> </aura:component>Controller (MapNearbyAccount.js)
({ init: function (cmp, event, helper) { var recordId = cmp.get("v.recordId"); var action = cmp.get("c.getAccounts"); action.setParams({recordId :recordId}); cmp.set('v.mapMarkers', [{location: {}}]); action.setCallback(this, function(response){ var accounts = response.getReturnValue(); var markers = []; for(var i = 0; i < accounts.length; i++){ var acc = accounts[i]; markers.push({ location: { Country : acc.BillingCountry, State : acc.BillingState, City: acc.BillingCity, Street: acc.BillingStreet }, icon : "standard:account", value: acc.Id, title: acc.Name, description:acc.Description }); } if(markers.length != 0){ cmp.set('v.mapMarkers', markers); } }); $A.enqueueAction(action); }, handlerMarkerSelect: function (cmp, event, helper) { console.log(event.getParam("selectedMarkerValue")); } });ApexClass (MapNearbyAccountController)
public class MapNearbyAccountController { @AuraEnabled public static List<Account> getAccounts(String BillingCity, String BillingState, String recordId){ Account acct = [SELECT Id, Name, BillingCountry, BillingState, BillingCity, BillingStreet, Industry FROM Account WHERE Id =:recordId]; return [SELECT Id, Name, BillingCountry, BillingState, BillingCity, BillingStreet,Description FROM Account WHERE BillingState = :acct.BillingState AND BillingCity LIKE :('%' + acct.BillingCity + '%') AND Industry = :acct.Industry LIMIT 10]; } }TestClass
@isTest public class MapNearbyAccountControllerTest { @isTest static void testMapNearbyAccountController() { Account acc1 = new Account(); acc1.Name='acc1'; acc1.BillingCity='Shibuya'; acc1.BillingState='Tokyo'; insert acc1; MapNearbyAccountController ctrl = new MapNearbyAccountController(); Test.startTest(); List<Account> getAccounts = ctrl.getAccounts(); System.assertEquals(false,getAccounts.isEmpty()); Test.stopTest(); } }
Please use the below test class:
Thanks,
Maharajan.C
All Answers
https://rajvakati.com/2018/09/26/creating-google-maps-with-lightningmap-component/ as this seems to be implementation.
Hope this helps.
Please use the below test class:
Thanks,
Maharajan.C
public class LightningMapCntrl {
Public String accountIds{get;set;}
public LightningMapCntrl(ApexPages.StandardSetController cntlr){
List<Account>selAccounts = cntlr.getSelected(); //get selected records from account list view
accountIds = '';
for(Account acc : selAccounts){
accountIds += acc.Id + '-'; //build list of ids string concatenated with comma
}
accountIds = accountIds.removeEnd('-');
system.debug('+++ IDs : ' + accountIds) ;
}
@auraEnabled
public static List<Account> getAccountList(String accountIds){
system.Debug('++++ accountIds : ' + accountIds);
List<String> accountIdList = accountIds.split('-');
return [Select Id, Name, type , BillingCity, BillingStreet,BillingPostalCode,BillingCountry, BillingState from account where Id In: accountIdList ];
}
}
Currently, i am displaying only opportunity name and marker on map using location (Address fields salesforce). But how to display stagename and other fields on maps). Please advise.
nice
Click here to check latest New sarkari Yojana (https://newsarkariyojna.site/)