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
Saurabh Sood 12Saurabh Sood 12 

Unable to get data from apex controller while I'm setting parameters with the help of setParams of recordId, I'm getting null recordId in apex controller

Aura App
<aura:application extends="force:slds">
    <c:myContactCmp recordId='0017F00000S7UjN'/>

<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId" controller="myContactController" access="global" >
    <aura:handler name="init" action="{!c.getContactList}" value="{!this}" />
    <aura:attribute name="contactList" type="List"/>

Component controller 
    getContactList: function(component, event, handler) {
        var action = component.get("c.ContactsList");
        //var accId = component.get("v.recordId");
        alert('acc id '+ component.get("v.recordId"));
            accId : accId
                action.setParams({ AccountId : component.get("v.recordId") });

        action.setCallback(this, function(response){
            var state = response.getState();
            if(state == 'SUCCESS'){
                var contactList = response.getReturnValue();
                //alert("From server: " + contactList);
               //console.log("From server: " + contactList);
               component.set("v.contactList", contactList);
                alert('alert in getting data');

Apex Controller

It's shows null recordId 

public class myContactController {
    public static List<Contact> ContactsList(Id accountId){
        system.debug('acc id is '+accountId);
        List<Contact> contacts = [SELECT ID,name,AccountId,Phone,Email from Contact where accountId =: accountId];
        return contacts;
Hi Saurabh,

While setting parameter from Component controller you used:- 

action.setParams({ AccountId : component.get("v.recordId") });

and in 'myContactController'  you defined property as -
public static List<Contact> ContactsList(Id accountId){}

So the problem is too small but that creating impact on getting recordId.
You just need to make "AccountId" as "accountId".

Replace  - action.setParams({ AccountId : component.get("v.recordId") });
action.setParams({ accountId: component.get("v.recordId") });

Let me know in case of any concerns.

Please mark this answer as the solution/ best answer if it solves your purpose so that it can help other community members.

Pramod Nishane
Salesforce Consultant
Varasi LLC