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
Rst123Rst123 

SObject row was retrieved via SOQL without querying field:Oppo​rtunityLin​eItem.Curr​encyIsoCod​e.

Hi,

I'm Getting below error :-

 

Error Message System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: OpportunityLineItem.CurrencyIsoCode

Class.SearchOpptyPageController.cOpportunity.<init>: line 530, column 1 Class.SearchOpptyPageController.getOpportunities: line 509, column 1 Class.SearchOpptyPageTest.opptyTest1: line 182, column 1

<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Controller Method due to which i'm getting error is :-

 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.

public List<cOpportunity> getOpportunities(){                  

opportunityList = new List<cOpportunity>();          

for(Opportunity o : (List<Opportunity>)con.getRecords()) {

            if(ModalityString != null || PortfolioString != null){       

          if(o.OpportunityLineItems.size() > 0){  

                       opportunityList.add(new cOpportunity(o));                  

    }               

}                

else{                                           

opportunityList.add(new cOpportunity(o));  <<<<<<<<<<ERROR-1 Line 509>>>>>>>>>>>>>>>>>                  

  }            

}               

   return opportunityList;      

}       

public Class cOpportunity{        

public Product2 opppr1 {get;set;}        

public Opportunity opp {get;set;}        

public Account acc1 {get;set;}         public Boolean selected{get;set;}        

public String convertPrice {get;set;}     

    //public Decimal convertPrice {get;set;}         

List<OpportunityLineItem> oppLineLst;       

  cOpportunity(Opportunity o){           

  convertPrice = '';        

     opp=o;           

  selected=false;         

   oppLineLst = [Select convertCurrency(TotalPrice),id,CurrencyIsoCode From OpportunityLineItem where OpportunityId =: o.Id];         

     oppLineLst = new   List<OpportunityLineItem>();         

    For(OpportunityLineItem ol :o.OpportunityLineItems){            

  Double conversionRate = [SELECT conversionrate,isocode FROM currencytype WHERE isocode =:ol.CurrencyIsoCode LIMIT 1].conversionRate;   <<<<<<<<<<<<<<ERROR -2 Line 530>>>>>>>>>>>>>    >>>>>>>>>>>>       

            

  //  if(!convertPrice.contains(String.ValueOf(ol.TotalPrice * conversionRate)))         

      if(ol.CurrencyIsoCode != 'USD')             

     convertPrice +=   '\n\r'+ (ol.TotalPrice * (1/conversionRate)).setscale(2)+'\n\r';      

          else                 convertPrice +=   '\n\r'+ (ol.TotalPrice).setscale(2) +'\n\r';       

      }             

        }

    }

Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox
Your original query didn't include the CurrencyISOCode field, which is what is causing the error. It looks like you're using the StandardSetController, in which case you need to include CurrencyISOCode in the query that populates the list; if you're using an automatic query by binding to fields, you need to bind to the field within the Visualforce page.