Start a conversation

Lookup Attributes Not Populating Due to Missing Fields in Custom SOQL Queries

Symptom

Lookup attributes (e.g., Plan, SLA) do not display values in the Solution Console, appearing blank or empty even though:
- The lookup configuration appears correct
- Debug logs show no obvious Apex exceptions
- Other attributes populate successfully

Additionally, Calculate Totals may fail or take an unusually long time to complete.

Cause

Custom lookup implementation classes (e.g., PriceItemLookup, PriceItemSLALookup) are missing required fields in their SOQL queries that retrieve Commercial Product (Price Item) records.

When a field is referenced in the Lookup Configuration (as a List Column or Search Column) but is not included in the SOQL query within the custom lookup class, Salesforce throws a runtime exception:

SObject row was retrieved via SOQL without querying the requested field: cspmb__Price_Item__c.<FIELD_NAME>

This exception occurs at the internal class level and only appears in subscriber logs, not in standard debug logs, making it difficult to diagnose.

Resolution

Step 1: Enable Subscriber Logging

To capture the actual exception:

  1. In Salesforce Setup, search for "Debug Logs"
  2. Click New to create a debug log
  3. Set the user to the affected user
  4. Set Apex Code log level to FINEST
  5. Set Visualforce log level to DEBUG
  6. Save and reproduce the issue

Step 2: Identify the Missing Field

  1. Reproduce the lookup issue (open the attribute in Solution Console)
  2. Download the subscriber debug log
  3. Search for "SObject row was retrieved via SOQL without querying the requested field"
  4. Note the field name mentioned in the error

Example error:

SObject row was retrieved via SOQL without querying the requested field: cspmb__Price_Item__c.ISP_Tag__c

Step 3: Locate the Custom Lookup Class

  1. Navigate to Setup > Custom Code > Apex Classes
  2. Find the lookup implementation class referenced in your attribute configuration
  3. Common patterns: PriceItemLookup, PriceItemSLALookup, <AttributeName>Lookup
  4. Open the class for editing

Step 4: Add the Missing Field to SOQL Queries

Search for all SOQL queries in the class that retrieve cspmb__Price_Item__c records and add the missing field to the SELECT clause.

Before:

List<cspmb__Price_Item__c> priceItems = [
    SELECT Id, Name, cspmb__Price_Item_Code__c
    FROM cspmb__Price_Item__c
    WHERE cspmb__Is_Active__c = true
];

After:

List<cspmb__Price_Item__c> priceItems = [
    SELECT Id, Name, cspmb__Price_Item_Code__c, ISP_Tag__c
    FROM cspmb__Price_Item__c
    WHERE cspmb__Is_Active__c = true
];

Important: Add the field to all SOQL queries in the class that retrieve Price Item records.

Step 5: Test the Fix

  1. Save the Apex class
  2. Navigate to the Solution Console
  3. Open the basket and access the attribute
  4. Verify the lookup now displays values correctly
  5. Test Calculate Totals to ensure it completes successfully

Step 6: Review Lookup Configuration Consistency

To prevent future occurrences:

  1. Navigate to Setup > Custom Settings > Lookup Configuration
  2. For each lookup, verify that all fields referenced in:
  3. List Columns
  4. Search Columns
  5. Filter conditions

...are also included in the SOQL query within the associated custom lookup implementation class.

Additional Notes

  • Subscriber Logs Are Essential: This type of error does not appear in standard debug logs. Always check subscriber logs when lookup attributes fail silently.
  • Calculate Totals Issues: If Calculate Totals is stuck or taking too long, try clicking Abandon Save to abort the job, then retry after fixing the lookup issue.
  • Multiple Lookups: If multiple lookup attributes are affected, check each associated custom class for missing fields.
  • Code Review: When adding new fields to Lookup Configurations, always update the corresponding custom lookup class SOQL queries to include those fields.
Choose files or drag and drop files
Was this article helpful?
Yes
No
  1. Priyanka Bhotika

  2. Posted

Comments