You need to sign in to do that
Don't have an account?
Megsie
Aura navigation component pageReference error "Cannot read property 'setParams' of undefined"
Hi All,
I am new to Lightning/salesforce. Trying to navigate to another object page using pageReference but getting this error "This page has an error. You might just need to refresh it. [Cannot read property 'setParams' of undefined]" . Unable to get ti right following the developerguide sample. Thanks in advance!
Here are my controller and component:
Controller.js:
navigateBankAccount: function(component, event, helper) {
var navService = component.find("navService");
var pageReference = {
type: 'standard__objectPage',
attributes: {
objectApiName: 'Bank_Account__c',
actionName: 'list'
},
state: {
filterName: 'Recent'
}
};
var pageReference = component.get("v.pageReference");
event.preventDefault();
navService.navigate(pageReference);
},
----------------
Component :
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" controller = "CreateCustomerRecord" >
<lightning:button label="Bank Account" onclick="{!c.navigateBankAccount}"/>
<aura:attribute name="cust" type="Customer__c" default="{'sobjectType': 'Customer__c',
'Name': '',
'Phone__c': '',
'Email__c': '',
'Phone__c': '',
'StreetAddress__c':'',
'StreetAddress__c': '',
'City__c': '',
'State__c': '',
'Country__c':'',
'Pincode__c':'',
'AdditionalInfo__c':''}" access="global" />
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<aura:attribute name="pageReference" type="Object"/>
<lightning:navigation aura:id="navService"/>
<aura:attribute name="picklistValues" type="Object" />
<aura:attribute name="picklistValues1" type="Object" />
<c:PicklistComponent sObjectName="Customer__c" fieldName="State__c" picklistValues="{!v.picklistValues}"/>
<c:PicklistComponent sObjectName="Customer__c" fieldName="Country__c" picklistValues="{!v.picklistValues1}"/>
<aura:attribute name="birthday" type="Date" default=""/>
<lightning:input name = "name" label="Name"
value="{!v.cust.Name}"/>
<lightning:input name = "eMail" label="email"
value="{!v.cust.Email__c}"/>
<lightning:input name = "phone" label="Phone"
value="{!v.cust.Phone__c}"/>
<lightning:input name = "streetAddress" label="StreetAddress"
value="{!v.cust.StreetAddress__c}"/>
<lightning:input name = "city" label="City"
value="{!v.cust.City__c}"/>
<lightning:select value="{!v.cust.State__c}" label = "State">
<option value="">Choose one...</option>
<aura:iteration items="{!v.picklistValues}" var="i">
<option value="{!i.value}">{!i}</option>
</aura:iteration>
</lightning:select>
<lightning:select value="{!v.cust.Country__c}" label = "Country">
<option value="">Choose one...</option>
<aura:iteration items="{!v.picklistValues1}" var="item">
<option value="{!item.value}">{!item}</option>
</aura:iteration>
</lightning:select>
<lightning:input name = "pincode" label="Pincode"
value="{!v.cust.Pincode__c}"/>
<ui:inputDate aura:id="expdate" label="Birthday" class="field" value="{!v.cust.Birthda__c}" displayDatePicker="true" />
<lightning:input name = "additionalInfo" label="AdditionalInfo"
value="{!v.cust.AdditionalInfo__c}"/>
<ui:inputCheckbox name = "kycVerified" label="KYCverified" value="{!v.cust.KYCverified__c}"/>
<lightning:button label="Save Customer"
onclick="{!c.saveCustomer}"/>
</aura:component>
I am new to Lightning/salesforce. Trying to navigate to another object page using pageReference but getting this error "This page has an error. You might just need to refresh it. [Cannot read property 'setParams' of undefined]" . Unable to get ti right following the developerguide sample. Thanks in advance!
Here are my controller and component:
Controller.js:
navigateBankAccount: function(component, event, helper) {
var navService = component.find("navService");
var pageReference = {
type: 'standard__objectPage',
attributes: {
objectApiName: 'Bank_Account__c',
actionName: 'list'
},
state: {
filterName: 'Recent'
}
};
var pageReference = component.get("v.pageReference");
event.preventDefault();
navService.navigate(pageReference);
},
----------------
Component :
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" controller = "CreateCustomerRecord" >
<lightning:button label="Bank Account" onclick="{!c.navigateBankAccount}"/>
<aura:attribute name="cust" type="Customer__c" default="{'sobjectType': 'Customer__c',
'Name': '',
'Phone__c': '',
'Email__c': '',
'Phone__c': '',
'StreetAddress__c':'',
'StreetAddress__c': '',
'City__c': '',
'State__c': '',
'Country__c':'',
'Pincode__c':'',
'AdditionalInfo__c':''}" access="global" />
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<aura:attribute name="pageReference" type="Object"/>
<lightning:navigation aura:id="navService"/>
<aura:attribute name="picklistValues" type="Object" />
<aura:attribute name="picklistValues1" type="Object" />
<c:PicklistComponent sObjectName="Customer__c" fieldName="State__c" picklistValues="{!v.picklistValues}"/>
<c:PicklistComponent sObjectName="Customer__c" fieldName="Country__c" picklistValues="{!v.picklistValues1}"/>
<aura:attribute name="birthday" type="Date" default=""/>
<lightning:input name = "name" label="Name"
value="{!v.cust.Name}"/>
<lightning:input name = "eMail" label="email"
value="{!v.cust.Email__c}"/>
<lightning:input name = "phone" label="Phone"
value="{!v.cust.Phone__c}"/>
<lightning:input name = "streetAddress" label="StreetAddress"
value="{!v.cust.StreetAddress__c}"/>
<lightning:input name = "city" label="City"
value="{!v.cust.City__c}"/>
<lightning:select value="{!v.cust.State__c}" label = "State">
<option value="">Choose one...</option>
<aura:iteration items="{!v.picklistValues}" var="i">
<option value="{!i.value}">{!i}</option>
</aura:iteration>
</lightning:select>
<lightning:select value="{!v.cust.Country__c}" label = "Country">
<option value="">Choose one...</option>
<aura:iteration items="{!v.picklistValues1}" var="item">
<option value="{!item.value}">{!item}</option>
</aura:iteration>
</lightning:select>
<lightning:input name = "pincode" label="Pincode"
value="{!v.cust.Pincode__c}"/>
<ui:inputDate aura:id="expdate" label="Birthday" class="field" value="{!v.cust.Birthda__c}" displayDatePicker="true" />
<lightning:input name = "additionalInfo" label="AdditionalInfo"
value="{!v.cust.AdditionalInfo__c}"/>
<ui:inputCheckbox name = "kycVerified" label="KYCverified" value="{!v.cust.KYCverified__c}"/>
<lightning:button label="Save Customer"
onclick="{!c.saveCustomer}"/>
</aura:component>
All Answers
It did not work, Raj. Still getting the same error. Is it related to API version ? I am using Developer console from trailhead with API 45.
Note: Adding to a lightning app in dev console is giving error for the same but what matters is it to be worked in org.