You need to sign in to do that
Don't have an account?
Ashwani Pradhan
System.SObjectException: SObject row was retrieved via SOQL without querying the requested field
I am running below SOQL in Developer Console and its working fine -
SELECT MSRE_Contact__r.name, MSRE_Contact__r.MSRE_Company__c, MSRE_Contact__r.MSRE_Contact_Title__c, MSRE_Investor__r.name, MSRE_Investor__r.Parent.Name, MSRE_Investment__c, MSRE_Investment__r.Product2.name, MSRE_Contact_Relationship__c, MSRE_Distribution__c, MSRE_Quarterly__c, MSRE_Legal__c, MSRE_Tax__c, Webcast__c, MSRE_Annual_Meeting__c, MSRE_Adv_Committee__c, CreatedDate, LastModifiedDate, lastModifiedBy.Name, IsDeleted FROM MSRE_Correspondence__c
Now same query if I am using in Apex calss below error coming -
System.SObjectException: SObject row was retrieved via SOQL without querying the requested field. Asset.Name
Here Product2 is lookup in Investment(Asset). Why its working in Developer Console and not in Apex? Any help would be appreciated.
SELECT MSRE_Contact__r.name, MSRE_Contact__r.MSRE_Company__c, MSRE_Contact__r.MSRE_Contact_Title__c, MSRE_Investor__r.name, MSRE_Investor__r.Parent.Name, MSRE_Investment__c, MSRE_Investment__r.Product2.name, MSRE_Contact_Relationship__c, MSRE_Distribution__c, MSRE_Quarterly__c, MSRE_Legal__c, MSRE_Tax__c, Webcast__c, MSRE_Annual_Meeting__c, MSRE_Adv_Committee__c, CreatedDate, LastModifiedDate, lastModifiedBy.Name, IsDeleted FROM MSRE_Correspondence__c
Now same query if I am using in Apex calss below error coming -
System.SObjectException: SObject row was retrieved via SOQL without querying the requested field. Asset.Name
Here Product2 is lookup in Investment(Asset). Why its working in Developer Console and not in Apex? Any help would be appreciated.
if "Asset.Name" field is on MSRE_Correspondence__c object Please post your full code and line number where you are getting error.
NOTE:- you need to add field in above query.
You might have referred "Asset.Name" in the visualforce page using the controller or in the controller some where, which you didn't query. If "Asset" is a lookup on MSRE_Investment__c object then, you should add MSRE_Investment__r.Asset.Name in your query before using it.
Hope this helps.
Kind Regards,
Krishna.
Can you help me with proper syntax, please? Seems like the field needs to be in the query.
Current code:
public static void AddOrderNumber(Map<Id, Order__c> oldMap,list<Order__c> issListIn,boolean isnew,boolean isODSvccall) {
// List<Order__c> issListIn = [select id,Order_Number__c, from Order__c where id in :Ordermap.keyset()];
*The Query is in the commented line. Trying to save it, but unable to do so
You might be using a field some where in the Apex code, which you haven't included in the SOQL query. Review the code properly and add the missing field in the SOQL query. Post the complete code if you need further help on this.
Regards,
Krishna.