function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ken Koellner @ EngagewareKen Koellner @ Engageware 

Get Id field from object in lightning component code.

I have an attribute that's an sObject like --- 
<aura:attribute name="myAttr" type="MyCustomObject__c"/>

I can get to all the fields via API name except Id.  A reference like {!v.myAttr.id} does not work.  A reference like {!v.myAttr.Name} works fine.

Is there some magic word to get the Id field from an Object in Lighting.

 
Best Answer chosen by Ken Koellner @ Engageware
Alain CabonAlain Cabon
Hi,

It is just the lower/upper case problem most of the time.     {!v.myAttr.Id}   "I" upper case.
 

All Answers

Alain CabonAlain Cabon
Hi,

It is just the lower/upper case problem most of the time.     {!v.myAttr.Id}   "I" upper case.
 
This was selected as the best answer
Ken Koellner @ EngagewareKen Koellner @ Engageware
Yeah, I just figured that out.  I know JS is case sensitive.  I thought I had coded "Id" but I coded "id".

BTW, here's a real useful line of code I wrote to figure that out....
var keys = Object.keys(myAttr); alert(keys);

I put that in the controller righter after myAttr is assigned a value.