[SalesForce] Passing Record ID to lightning component

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 {
    @AuraEnabled
    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);
                }
            }

        });
        $A.enqueueAction(action);
    }
})

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?

Best Answer

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

Related Topic