+ Start a Discussion
SF Beginner 2019SF Beginner 2019 

getting null value on currentrecordid did i miss something

var action2 = component.get("c.getAccount");
        action2.setParams({
            "currentRecordId" : component.get("v.recordId")
        });
        action2.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                component.set("v.account", response.getReturnValue());
                console.log(response.getReturnValue());
            }
        });
        $A.enqueueAction(action2);
 
<aura:attribute name="account" type="Account" 
                    default="{ 'sobjectType': 'Account' }"/>
    <aura:attribute name="recordId" type="Id" />

    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    
    <div id="Modal_Parent" style="height:640px; width:1500px;">
        <section role="dialog" tabindex="-1" aria-labelledby="modal-heading-01" aria-modal="true" aria-describedby="modal-content-id-1" class="slds-modal slds-fade-in-open">
            <div class="slds-modal__container">
                <header class="slds-modal__header">
                    <h2 id="modal-heading-01" class="slds-text-heading_medium slds-hyphenate">Modal Test</h2>
                </header>
                <div class="slds-modal__content slds-p-around_medium" id="modal-content-id-1">
                    <p>Display the Name </p>
                    <force:outputField value="{!v.account.Name}"/>
                    {!v.account.Name}
                    <p></p>
                </div>

            </div>
 
@AuraEnabled
    public static List<Account> getAccount(String currentRecordId) {
        System.debug('AccountRecord' + currentRecordId);
        return [select Id, Name from Account where Id =: currentRecordId];
    }

 
Best Answer chosen by SF Beginner 2019
Raj VakatiRaj Vakati
try this code
 
public class AccountsController {
     @AuraEnabled
    public static List<Account> getAccount(String currentRecordId) {
        System.debug('AccountRecord' + currentRecordId);
        return [select Id, Name from Account where Id =: currentRecordId];
    }
 }
 
<aura:component controller="AccountsController">
        <aura:attribute name="accounts" type="List" />
        <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
            <aura:iteration items="{!v.accounts}" var="account">
			   <force:outputField value="{!account.Name}"/>
            </aura:iteration>
  </aura:component>
 
({
      doInit: function(component, event, helper) {
       var action2 = component.get("c.getAccount");
        action2.setParams({
            "currentRecordId" : component.get("v.recordId")
        });
        action2.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                component.set("v.accounts", response.getReturnValue());
            }
        });
        $A.enqueueAction(action2);
	   
      },
     
    })

 

All Answers

Raj VakatiRaj Vakati
try this code
 
public class AccountsController {
     @AuraEnabled
    public static List<Account> getAccount(String currentRecordId) {
        System.debug('AccountRecord' + currentRecordId);
        return [select Id, Name from Account where Id =: currentRecordId];
    }
 }
 
<aura:component controller="AccountsController">
        <aura:attribute name="accounts" type="List" />
        <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
            <aura:iteration items="{!v.accounts}" var="account">
			   <force:outputField value="{!account.Name}"/>
            </aura:iteration>
  </aura:component>
 
({
      doInit: function(component, event, helper) {
       var action2 = component.get("c.getAccount");
        action2.setParams({
            "currentRecordId" : component.get("v.recordId")
        });
        action2.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                component.set("v.accounts", response.getReturnValue());
            }
        });
        $A.enqueueAction(action2);
	   
      },
     
    })

 
This was selected as the best answer
SF Beginner 2019SF Beginner 2019
recordid was still null
 
Raj VakatiRaj Vakati
If you are testing it from the .app file you can pass the record id like below 

 
<aura:application extends="force:slds">
    <c:Yourcomponent_name recordId ="001" />
</aura:application>

 
Raj VakatiRaj Vakati
<c:Yourcomponent_name recordId ="001XXXXXXXXXXXXX" />

 
SF Beginner 2019SF Beginner 2019
Thank you so much! I have learned something new! by the way from the person account, if I have a field looked up to contact, is it possible to get one of those fields? for for example I want to get from that field is the date of birth. meaning like select id, contact.dateofbirth from account. thank you