function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Anu YadavAnu Yadav 

Soql not queried the requested field error but i am querying the field

hi Guys,

i have two classes. I m querying Title and MiddleName of Contact object in subquery for a Map "RelatedAccounts". these two fields i am using in ManageCustomerHandler class for mapping purpose. but i m getting the below error.

ERROR: ContactTrigger: execution of AfterUpdate caused by: System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Contact.Title

        list<Id> AccountIds = new list<Id>();
        for (Contact c : contacts){
            AccountIds.add(c.AccountId);
        }
        map<Id,Account> RelatedAccounts = new map<Id,Account>([SELECT Id,Name,Phone,Email__c,ABN__c,Fax,ACN__c,Website,FraudFlag__c,VIP_Customer__c,Account_UUID__c,Pref_Comm_Method__c,Data_Sovereign_Status__c,ABN_Overide__c,Type,Customer_ID__c,Ultimate_Parent_CIDN__c,Is_TCM_Fields_Changed__c,Business_Unit__c,Managed__c,Language_Preference__c,Market_Segment__c,Customer_Status__c,Legacy_SOU__c,CIDN__c,Parent_CIDN__c,Legacy_Ownership_Code__c,PriorityAssist__c,Churn_Propensity__c,Date_Started_Trading_with_Telstra__c,Description,Franchisee_Arrange__c,Retired_User_ID__c,Retirement_Reason__c,Time_Zone__c,Wriiten_Auth_Required__c,Effective_Retired_Date__c,Customer_Last_Verified_Date__c,Legacy_Created_date__c,Legacy_ROU__c,Customer_Potential_Revenue__c,Customer_Current_Revenue__c,Partners__c,Approve_Decline_Reason__c,Recommended_Payment_Method__c,Recommended_Billing_Frequency__c,Validation_Customer_Consent__c,Validation_Consent_Request_Date__c,Customer_Effective_Start_Date__c,Relationship_Type__c,Reporting_Point_Indicator__c,Customer_Effective_EndDate__c,Date_of_Application__c,Geographical_LocationCode__c,TCM_Master_ID__c,loc__c,TCM_Last_Updated__c,OLB_Online_Bill_Registered__c,Credit_Limit__c,Credit_Management_Status__c,Credit_Rating__c,Concession_Authority__c,Concession_Number__c,Concession_Type__c,Payment_Type__c,Payment_Status__c,Valid_Concession_Flag__c,Last_Validated_Date__c,Bypass_Concession_Validation__c,Validation_Result_Override__c,Portfolio_Code__c,Primary_Portfolio_Indicator__c ,(Select Id,Title,FirstName,MiddleName,LastName,Birthdate,Driver_License_Id__c,Driver_License_State__c,Contact_Type__c From Contacts) FROM Account WHERE Id IN :AccountIds]);
     
 if(c.Contact_Type__c == 'Legal Lessee' && RelatedAccount.Type == 'Sole Trader'){ 
                    System.debug('for sole trader customers contact' +c);
                    CustomermcReq = ManageCustomerHandler.generateManageCustomerRequest(RelatedAccount, event);
                }

class: ManageCustomerHandler
 ManageCustomerRequest.CustomerAccount customerAccountItem = new ManageCustomerRequest.CustomerAccount();
        if(cont != null && (a.Type =='Sole Trader' || a.Type =='Residential')){
            customerAccountItem.title = stripNulls(cont.Title);
             System.debug('Fistname++'+cont.FirstName);
            customerAccountItem.firstName = stripNulls(cont.FirstName + ' ' +cont.MiddleName);
            customerAccountItem.birthDate = '';
            if(cont.Birthdate != null){
              customerAccountItem.birthDate = String.valueOf(cont.Birthdate);     
            }
            customerAccountItem.driverLicenseNumber = cont.Driver_License_Id__c;
           customerAccountItem.driverLicenseState = cont.Driver_License_State__c;
               
            //customerAccountItem.phoneNumber = stripNulls(cont.Phone);
          }
I have checked User Interface for Middle Name. it is enabled. and Field permission is proper.

Thanks,
Anu
PawanKumarPawanKumar
i think the below line is creating problem. So please make sure method inside ManageCustomerRequest. CustomerAccount() , you are querying title field again.

 customerAccountItem.title = stripNulls(cont.Title);
Anu YadavAnu Yadav
ManageCustomerRequest is a normal request class having request structure.

public class CustomerAccount
    {
        public String title;
        public String firstName;
        public String lastName;
        public String birthDate;
        public String phoneNumber;
        public String faxNumber;
        public String emailAddress;
        public String abn;
        public String acn;
        public String webAddress;
        public String driverLicenseNumber;
        public String driverLicenseState;
        public String fraudFlag;
        public String vipFlag;
        public String accountUuid;
        public String preferredMethod;
        public String dataSovereignty;
    }

cant do query there.