Problem: This error generally occurs when you are using a field in the logic without quering that field in its related SOQL query.
Example:
Account a = [Select id,name from Account limit 1];
if(a != null) {
if(a.rating =='Cold') {
System.debug('Rating is Cold');
}
}
In the above code, line 3 rating field is referred but it's not queried in the soql query at line 1.
Updated Code:
Account a = [Select id,name,rating from Account limit 1];
if(a != null) {
if(a.rating =='Cold') {
System.debug('Rating is Cold');
}
}
Output:
No comments:
Post a Comment