You need to sign in to do that
Don't have an account?
Cole Prato
Cannot read property 'Product_Version__c' of undefined Component Error
Hi,
I am getting this error:
Uncaught Error in $A.getCallback() [Cannot read property 'Product_Version__c' of undefined]
Callback failed: apex://dynamicCardController/ACTION$getCaseDetails
I have a lightning component on the page that uses an Apex Controller to Grab Account Detials and Display on the Case Page.
I am only getting this error when the case does not have an account. I tired only to display the component when there is an account but still getting these errors.
End Goal is for me not to get the error on the page, since there would be no way to display the data without an account on the case.
Helper Code:
({
getCaseDetails : function(cmp, event) {
var recordId = cmp.get('v.recordId');
var getCaseDetails = cmp.get('c.getCaseDetails');
getCaseDetails.setParams({
recordId : recordId
})
getCaseDetails.setCallback(cmp, function(response) {
var state = response.getState();
if (state === 'SUCCESS') {
var results = response.getReturnValue();
cmp.set('v.AccountId', results.AccountId);
cmp.set('v.ProductVersion', results.Account.Product_Version__c);
} else
console.log(response);
})
$A.enqueueAction(getCaseDetails);
}
})
I am getting this error:
Uncaught Error in $A.getCallback() [Cannot read property 'Product_Version__c' of undefined]
Callback failed: apex://dynamicCardController/ACTION$getCaseDetails
I have a lightning component on the page that uses an Apex Controller to Grab Account Detials and Display on the Case Page.
I am only getting this error when the case does not have an account. I tired only to display the component when there is an account but still getting these errors.
End Goal is for me not to get the error on the page, since there would be no way to display the data without an account on the case.
Helper Code:
({
getCaseDetails : function(cmp, event) {
var recordId = cmp.get('v.recordId');
var getCaseDetails = cmp.get('c.getCaseDetails');
getCaseDetails.setParams({
recordId : recordId
})
getCaseDetails.setCallback(cmp, function(response) {
var state = response.getState();
if (state === 'SUCCESS') {
var results = response.getReturnValue();
cmp.set('v.AccountId', results.AccountId);
cmp.set('v.ProductVersion', results.Account.Product_Version__c);
} else
console.log(response);
})
$A.enqueueAction(getCaseDetails);
}
})
I think the problem is ==> If there is no Account is related to the case then you are getting this error:
So just add the Account null check in your JS.
({
doInit : function(cmp, event) {
var recordId = cmp.get('v.recordId');
var getCaseDetails = cmp.get('c.getCaseDetails');
getCaseDetails.setParams({
recordId : recordId
})
getCaseDetails.setCallback(cmp, function(response) {
var state = response.getState();
if (state === 'SUCCESS') {
var results = response.getReturnValue();
alert( ' ==> results' + JSON.stringify(results) );
if(results.AccountId != null )
{
cmp.set('v.AccountId', results.AccountId);
cmp.set('v.ProductVersion', results.Account.Product_Version__c);
}
} else
console.log(response);
})
$A.enqueueAction(getCaseDetails);
}
})
Thanks,
Maharajan.C
All Answers
public class dynamicCardController {
@AuraEnabled
public static Case getCaseDetails(Id recordId) {
Case c = [SELECT Id, AccountId, Account.Product_Version__c FROM Case WHERE Id =: recordId];
return c;
}
}
I think the problem is ==> If there is no Account is related to the case then you are getting this error:
So just add the Account null check in your JS.
({
doInit : function(cmp, event) {
var recordId = cmp.get('v.recordId');
var getCaseDetails = cmp.get('c.getCaseDetails');
getCaseDetails.setParams({
recordId : recordId
})
getCaseDetails.setCallback(cmp, function(response) {
var state = response.getState();
if (state === 'SUCCESS') {
var results = response.getReturnValue();
alert( ' ==> results' + JSON.stringify(results) );
if(results.AccountId != null )
{
cmp.set('v.AccountId', results.AccountId);
cmp.set('v.ProductVersion', results.Account.Product_Version__c);
}
} else
console.log(response);
})
$A.enqueueAction(getCaseDetails);
}
})
Thanks,
Maharajan.C