I am trying to implement Google Maps with lightning component and need to retrieve the record id in order to use it in the hyperlink in map marker but I am not able to access the record id in lightning controller. Here's the part of code that's doing this job

Apex class-

public with sharing class GoogleMap {
    public static List<Account> getAccounts(){

        return [select id,Phone, name, BillingLatitude, BillingLongitude from Account limit 10];

Lightning app controller js-

    doInit: function(component, event, helper) {
        console.log('Here 1');
        var action = component.get('c.getAccounts');

        action.setCallback(this, function(response){
            var state = response.getState();
            console.log('state:', state);
            if (state == "SUCCESS") {
                var acc = response.getReturnValue();

                if(acc.length > 0){
                   console.log('acc'+ acc[0].ID);

                    var mapOptionsCenter = {"lat":parseFloat(acc[0].BillingLatitude), "lng":parseFloat(acc[0].BillingLongitude)};
                    var mapData = Array();
                    //cmp.set("v.opportunities", response.getReturnValue());
                    for(var i=0; i<acc.length; i++){
                        mapData.push({"lat":parseFloat(acc[i].BillingLatitude), "lng":parseFloat(acc[i].BillingLongitude), "markerText":acc[i].recordid})

                    component.set('v.mapOptionsCenter', mapOptionsCenter);
                    component.set('v.mapData', mapData);
                    component.set('v.acc', acc);


So when I try to access console.log('acc'+ acc[0].ID), it says the id is undefined. Any idea how to access the id here?

1 Answer 1


Lightning is JavaScript, and as such, is case sensitive. The field name is not "id" or "ID" or "iD", but specifically "Id".

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .