You need to sign in to do that
Don't have an account?
Error when updating Apex Class to include a new field
I'm getting the following error when I run a debug log on an update to an APEX Class, FATAL_ERROR|System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Account.Account_Owner_For_Jiva__c
The field is a formula text field that brings in the account owners email address. We use this to pass the email to our external system. I added the field the existing APEX Class like this:
//json container for Account
private class AccountCompany{
private Id SalesforceID; //required
private String Name; //required
private String AccountOwner; //required
private String PrimaryCountry; //required
//private String EAGRelationshipID;
private String UnicodeName;
private String IndustrySectorID;
private String ManufacturingTypeID;
public AccountCompany(Sobject record)
{
Account account = (Account)record;
this.SalesforceID = account.Id;
this.Name = account.Name;
this.PrimaryCountry = account.Primary_Country__c;
this.AccountOwner = account.Account_Owner_For_Jiva__c;
//this.EAGRelationshipID = EAGRelationshipID; //no related field in salesforce
this.UnicodeName = account.Account_Name_Unicode__c;
this.IndustrySectorID = account.Industry_Sector_ID__c;
this.ManufacturingTypeID = account.Manufacturing_Type_ID__c;
}
}
The updated Class saves with no errors, but was not communicating correctly which is when I ran the code debug log. I saw where I need to add it to the query, but I don't see anything else in the class that includes the existing fields.
Kindly review below mentioned workaround to fix 'SObject row retrieved via SOQL without querying the requested field' error.
https://help.salesforce.com/articleView?id=000328927&language=en_US&type=1&mode=1
Thanks,
Vinay Kumar
Please check your SOQL, you may not querying the field (Account_Owner_For_Jiva__c) and trying to access that in your code.
Hope this helps!
Thanks,
Sucharita
//retrieves list of fields for the specified object type that
//should be included in the web request
private static String retrieveObjectFields(String objectType)//, Map<String, String> sforceToWebFieldMap)
{
String selectFields = '';
//TO DO: WILL REMOVE Webservice_Parameter_Name__c field before deploy
JIVA_Field__mdt [] jivaFieldsForObject = [Select MasterLabel, isStandardField__c /*, Webservice_Parameter_Name__c*/
From JIVA_Field__mdt Where Object_API_Name__c =: objectType];
for(JIVA_Field__mdt field: jivaFieldsForObject)
{
String fieldAPIName = field.isStandardField__c ? field.MasterLabel : field.MasterLabel + '__c';
if(field.MasterLabel != 'Id')
{
selectFields += ', ' + fieldAPIName;
}
//sforceToWebFieldMap.put(fieldAPIName, field.Webservice_Parameter_Name__c);
}
return selectFields;
}
private static Boolean runningInASandbox() {
return [SELECT Id, IsSandbox FROM Organization LIMIT 1].IsSandbox;
}
//json container for Account
private class AccountCompany{
private Id SalesforceID; //required
private String Name; //required
private String AccountOwner; //required
private String PrimaryCountry; //required
//private String EAGRelationshipID;
private String UnicodeName;
private String IndustrySectorID;
private String ManufacturingTypeID;
public AccountCompany(Sobject record)
{
Account account = (Account)record;
this.SalesforceID = account.Id;
this.Name = account.Name;
this.PrimaryCountry = account.Primary_Country__c;
this.AccountOwner = account.Account_Owner_For_Jiva__c;
//this.EAGRelationshipID = EAGRelationshipID; //no related field in salesforce
this.UnicodeName = account.Account_Name_Unicode__c;
this.IndustrySectorID = account.Industry_Sector_ID__c;
this.ManufacturingTypeID = account.Manufacturing_Type_ID__c;