What can be the cause of the error: System.SObjectException: SObject row was retrieved via SOQL without invoking the requested field?
I am getting the below-mentioned error, which looks like this:
Line: 4, Column: 1 System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Service_Contract_Products__c.Installed_Product__r. But when I am running the same code inside a class, I am not getting the error.
I am running this code with the logic that a Covered Product is an object. The installed product is the field present in Covered Product, and its status is the picklist field on the installed product.
Can I get any solution regarding this problem?
You may get the error: SObject row was retrieved via SOQL without querying the requested field because your query does not contain the code asking for the related record, which is known as Installed_Product_c. The related record is an id of the specific record. But you need to include _r reference like Installed_Product_r.Status_c in the code for asking the query. Also, every field should be in a SOQL query. The value of the Installed_Product_r.Status_c has a value which is checked by the if condition. So, add that field first. However, you can use the WHERE clause to get the records in the Installed Product.