[SalesForce] action.SetParams not passing parameter through to Apex Class as expected

I'm currently modifying a Lightning Component that someone else created. As such, I'm trying to get the hang of how to work with Aura as I haven't done it before – only Apex and a bit of Visualforce.

Essentially, I have an initial screen which prompts record type selection. In the controller for this screen I have the 'redirect' function, which (after some other code), does the following:

var splitArray = recordTypeID.split("/");
//recordTypeID is the ID of the record type the user selects.
var navService = component.find("navService");
var pageReference = {
    type: 'standard__component',
    attributes: {
        componentName: 'c__PersonWizard'
    },
    state:{
        "c__recordTypeID":splitArray[1]
    }
};

event.preventDefault();
navService.navigate(pageReference);

This will redirect the user to the PersonWizard component. The first page should display a table of Contacts and provides a search box at the top to search for a Contact. At the moment, this table is not filtered based on anything. However, I want to filter it to only Contacts with the record type chosen by the user.

The PersonWizard uses a controller class (Javascript) – whose doInit function runs a helper method called 'getDataTableData' (this is the method that gets all the Contact data to display in the initial table of Contacts shown to the user. The getDataTable function includes this code:

var recordTypeIdVar = component.get("v.pageReference.state.c__recordTypeID");
var action = component.get("c.getDataTableDetails");
console.log('Record Type ID Passed Through to getTableDataDetails(Apex): '+recordTypeIdVar);
action.setParams({
    objectName:'Contact',
    fieldSetName:'Contact_Wizard_List_View',
    recordTypeId:recordTypeIdVar,
    pageNumber:pageNumber,
    pageSize:pageSize,
});

... some more code that's not relevant to the issue...

$A.enqueueAction(action);

Now, when I check the console output, I can see that the 'log' command in line 3 is logging the recordTypeId value correctly:

"Record Type ID Passed Through to getTableDataDetails(Apex): 0126F000000iWXvQAM"

The Apex class (getDataTableDetails) includes the 'recordTypeId' String parameter as one of its arguments, as well as objectName, fieldSetName, pageNumber and pageSize. I have included a System.debug() line at the start of the method which prints the value of the recordTypeId argument. Here is the problem: that argument is null when I run the wizard:

Record Type ID Passed Through to getDataTableDetails: null

So it seems that the Javascript helper class is able to obtain the recordTypeId value from the Pagereference. However, when it tries to set that value as one of the parameters for the action (running the Apex function), it doesn't pass through anything. Can anyone help me as to why this might be happening? Is my syntax on action.setParams() correct?

Thanks a lot in advance.

Best Answer

So clearing my cookies solved this issue. Thanks everyone for the help.

Related Topic