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
balraj singh 33balraj singh 33 

component.Find is giving undefined

I am trying to find field value by using aura:id but i am getting an error as 
component.find("aura:id") is giving undefined.


Here i my component : 

<lightning:recordEditForm  aura:id="form" recordId="{!v.recordId}" objectApiName="Contact" density="compact" 
                              onsuccess="{!c.handleSuccess}" onerror="{!c.handleError}" onsubmit="{! c.handleSave }" >
        <!-- <aura:if isTrue="{!v.isEditPage}">
            <lightning:messages />
        </aura:if>-->
        
        <!--Detail Panel-->
        
        <lightning:accordion aura:id="accordion" activeSectionName="{!v.activeSections}" allowMultipleSectionsOpen="true">
            
            <!--Detail Section-->               
            <lightning:accordionSection name="A" label="Detail">            
                <aura:set attribute="actions">
                    <aura:if isTrue="{!v.isEditPage}">
                        <lightning:buttonIcon iconName="utility:save" variant="bare" alternativeText="" type="submit" />
                        <aura:set attribute="else">
                            <lightning:buttonIcon iconName="utility:edit" variant="bare" onclick="{! c.changeEditLayout }"
                                                  alternativeText="Edit" />
                        </aura:set>
                    </aura:if>
                </aura:set>
                <ui:scrollerWrapper class="scrollerSize">
                    <div class="slds-grid slds-gutters slds-wrap">
                        
                        <!-- LEFT COLOUMN DETAIL-->
                        
                        <div class="slds-col slds-size_1-of-1 slds-large-size_6-of-12">
                            <!--div class="slds-col slds-size_6-of-12"-->
                            
                            <div class="slds-border_bottom">
                                <aura:if isTrue="{!v.isEditPage}">
                                    <lightning:inputField aura:id="FirstName" value="{!v.FirstName}"
                                                          fieldName="FirstName" 
                                                          required="true"/>
                                    <lightning:inputField aura:id="LastName" value="{!v.LastName}"
                                                          fieldName="LastName" />
                                    <!-- <lightning:inputName aura:id="myname" label="Full Name" firstName="{!v.FirstName}"
                                                         lastName="{!v.LastName}"
                                                         fieldsToDisplay="{!v.fields}" required="true" /> -->
                                    <aura:set attribute="else">
                                        <lightning:outputField aura:id="Name1" value="{!v.Name}" fieldName="Name" />
                                    </aura:set>
                                </aura:if>
                            </div>
              <div class="slds-border_bottom">
                                <aura:if isTrue="{!v.RFSet}">
                                    <lightning:outputField aura:id="Current_Firm__c" value="{!v.Current_Firm__c}"
                                                           fieldName="Current_Firm__c" />
                                </aura:if>
                                <aura:if isTrue="{!not(v.RFSet)}">
                                    <aura:if isTrue="{!v.isEditPage}">
                                        <lightning:inputField aura:id="Current_Firm__c1" value="{!v.Current_Firm__c}"
                                                              fieldName="Current_Firm__c" onchange="{!c.handleChange}"/>
                                        <aura:set attribute="else">
                                            <lightning:outputField aura:id="Current_Firm__c2" value="{!v.Current_Firm__c}"
                                                                   fieldName="Current_Firm__c" />
                                        </aura:set>
                                    </aura:if>
                                </aura:if>
                            </div>
Controller : 

handleChange : function(component, event, helper) {
        console.log( "inside handleCurrentFirmChange");        
    
     var fNameAttValue = component.Find("FirstName");
        
        console.log('First Name : ' +fNameAttValue);
Sai PraveenSai Praveen (Salesforce Developers) 
Hi,

Can you share the entire code of the component. I guess some part of the component code is missing. If we have the entire code we can try in our personal org and give you the exact solution.

Thanks,
 
mukesh guptamukesh gupta
Hi Balraj,

Instead of
var fNameAttValue = component.Find("FirstName");


Please use below line
var fNameAttValue = component.Find("FirstName").get("v.value")

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh