You need to sign in to do that
Don't have an account?
Jason Kuzmak 12
Apex lookup reference fields still showing null even after being queried
I am working with fields in Salesforce CPQ, though I figure all of the custom objects contained in it should respond to Apex as any others would. For some reason though, every time I try to reference a field on a product referenced by one of the custom objects, all fields related to that product show as null. I'm probably making some really obvious mistake. Please take a look:
public without sharing class QuoteLineHandler { public static void HandleBeforeDelete(){ // Removes the Product type of all "Mosca Model" quote line items from the "Product Names" field on quote level List<SBQQ__QuoteLine__c> quoteLineList = new List<SBQQ__QuoteLine__c>(); List<Id> productIds = new List<Id>(); // Add all relevant lines to list for further processing for(SBQQ__QuoteLine__c delQuoteLine : (List<SBQQ__QuoteLine__c>)Trigger.old){ quoteLineList.add(delQuoteLine); productIds.add(delQuoteLine.SBQQ__Product__c); } List<Product2> productList = [Select Id,Name,Product_Type__c From Product2 Where Id In :productIds]; System.debug('productList query size is ' +productList.size()+ ' and product list = ' +productList); for(SBQQ__QuoteLine__c ql : quoteLineList){ System.debug('checking if quoteline product name is null. Cover thy bases lest ye should receive a null-pointer exception.'); System.debug('ql.SBQQ__Product__c = '+ql.SBQQ__Product__c+ ' AKA ' + ql.SBQQ__Product__r.Name); System.debug('ql.Id = ' +ql.Id); if(ql.SBQQ__Product__r.Name != null){ System.debug('This code is never reached. Product name is always null."); } } } }As the last debug says, my null check never passes. My product's name is always null in spite of the fact that it shows in my query as having a name. Help would be greatly appreciated.
All Answers
Wouldn't that be what the Product2 SOQL Query does for me? I neglected to mention that the SBQQ__Product__c is a lookup to this object, but I reckon that querying the product object as shown would get me the fields I'm trying to reference. I'm not sure why it doesn't.
I figured out what you meant, though I can't delete the question now so I'll just go over it. Even when queried, the system still can't recognize how the queried information relates to the objects I'm trying to reference, so it's up to me to either map them together, or to only work with the data that I have just queried.