Discussions
- General Development
- Schema Development
- Apex Code Development
- Visualforce Development
- Formulas & Validation Rules
- Security
- Mobile
- Force.com Sites & Site.com
- Chatter Development
- Java Development
- .NET Development
- Perl, PHP, Python & Ruby
- Desktop Integration
- APIs and Integrations
- Visual Workflow
- Apple, Mac and OS X
- VB and Office Development
- AppExchange Directory & Packaging
- Salesforce Labs & Open Source Projects
- Other Salesforce Applications
- Jobs Board
- Force.com Discussion Boards
- :
- Developer Boards for Force.com and Database.com
- :
- Apex Code Development
- :
- Re: SObject row was retrieved via SOQL without que...
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
SObject row was retrieved via SOQL without querying the requested field
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-09-2012 10:30 PM
Hi,
I have writtern an Extension class for opportunity visual force page.
I have used 4 custom picklist fields of opportunity on vf page, fields names are Product_Group__c,Product_Area__c,Product_Family__c
My problem is when I am running the test class is throwing an exception
SObject row was retrieved via SOQL without querying the requested field: Opportunity.Product_Group__c.
Class.opportunityProductEntryExtension.updateAvail
public opportunityProductEntryExtension(ApexPages.StandardController controller)
{
objOpp= (Opportunity)controller.getRecord();
// Need to know if org has multiple currencies enabled
multipleCurrencies = UserInfo.isMultiCurrencyOrganization();
// Get information about the Opportunity being worked on
if(multipleCurrencies)
theOpp = database.query('select Id, Product_Group__c, Product_Area__c, Product_Family__c , Product_Family_Child__c, Pricebook2Id, Pricebook 2.Name, CurrencyIsoCode from Opportunity where Id = \'' + controller.getRecord().Id + '\' limit 1');
else
theOpp = [select Id,Product_Group__c,Product_Area__c, Product_Family__c, Product_Family _Child__c, Pricebook2Id, PriceBook2.Name from Oppo rtunity where Id = :controller.getRecord().Id limi t 1];
// If products were previously selected need to put them in the "selected products" section to start with
shoppingCart = [select Id,Product_Group__c,Product_Area__c,Product_families__c,Product_Child __c, Quantity, TotalPrice, UnitPrice, Description, PriceBookEntryId, PriceBookEntry.Name, PriceBookE ntry.IsActive, PriceBookEntry.Product2Id, PriceBoo kEntry.Product2.Name, PriceBookEntry.PriceBook2Id from opportunityLineItem where OpportunityId=:theO pp.Id];
// Check if Product hierarchy picklist ischanged
// Check if Opp has a pricebook associatedyet
if(theOpp.Pricebook2Id == null){
Pricebook2[] activepbs = [select Id, Name from Pricebook2 where isActive = true limit 2] ;
if(activepbs.size() == 2){
forcePricebookSelection = true;
theBook = new Pricebook2();
}
else{
theBook = activepbs[0];
}
}
else{
theBook = theOpp.Pricebook2;
}
if(!forcePricebookSelection)
updateAvailableList();
}
public void updateAvailableList()
{
//objOpp= (Opportunity)controller.getRecord();
String qString;
// We dynamically build a query string andexclude items already in the shopping cart
String idOpp=System.currentPageReference().getParameters().get('id');
Opportunity oppList=[SELECT Product_Group__c, Product_Area__c, Product_Family__c,
Product_Family_Child__c FROM opportunity
where id=:idOpp limit 1];
String sProductGroup =oppList.Product_Group__c;
String sProductArea = oppList.Product_Area__c;
String sProductFamily = oppList.Product_Family__c;
String sProductChild = oppList.Product_Family_Child__c;
If(oppList.Product_Group__c !=null && oppList.Product_Area__c!='Multiple' && oppList.Product_ Family__c!='Multiple' && oppList.Product_Family_Ch ild__c!='Multiple')
{
qString = 'select Id, Pricebook2Id, IsActive, Product2.Name, Product2.Family, Product2.I sActive, Product2.Description, UnitPrice from Pric ebookEntry where IsActive=true and Product2.Produc t_Group__c= \'' + sProductGroup + '\' and Product2 .Product_Area__c= \'' + sProductArea + '\' and Pr oduct2.Product_Family__c= \'' + sProductFamily + '\' and Product2.Product_Family_Child__c =\''+ sP roductChild+ '\' and Pricebook2Id = \'' + theBook. Id + '\'';
if(multipleCurrencies)
qstring += ' and CurrencyIsoCode =\'' + theOpp.get('currencyIsoCode') + '\'';
// note that we are looking for the search string entered by the user in the name OR des cription
// modify this to search other fieldsif desired
if(searchString!=null)
{
qString+= ' and (Product2.Name like \'%' + searchString + '%\' or Product2.productco de like \'%' + searchString + '%\')';
}
}
If(oppList.Product_Area__c!='Multiple' && oppList.Product_Family__c!='Multiple' && oppList.P roduct_Family_Child__c=='Multiple')
{
qString = 'select Id, Pricebook2Id, IsActive, Product2.Name, Product2.Family, Product2.Is Active, Product2.Description, UnitPrice from Price bookEntry where IsActive=true and Product2.Product _Group__c= \'' + sProductGroup + '\' and Product2. Product_Area__c= \'' + sProductArea + '\' and Pro duct2.Product_Family__c= \'' + sProductFamily + ' \' and Pricebook2Id = \'' + theBook.Id + '\'';
if(multipleCurrencies)
qstring += ' and CurrencyIsoCode =\'' + theOpp.get('currencyIsoCode') + '\'';
// note that we are looking for the search string entered by the user in the name OR des cription
// modify this to search other fieldsif desired
if(searchString!=null)
{
qString+= ' and (Product2.Name like \'%' + searchString + '%\' or Product2.productco de like \'%' + searchString + '%\')';
}
}
if(oppList.Product_Area__c!='Multiple' && oppList.Product_Family__c=='Multiple')
{
qString = 'select Id, Pricebook2Id, IsActive, Product2.Name, Product2.Family, Product2.Is Active, Product2.Description, UnitPrice from Price bookEntry where IsActive=true and Product2.Product _Group__c= \'' + sProductGroup + '\' and Product2. Product_Area__c= \'' + sProductArea + '\' and Pri cebook2Id = \'' + theBook.Id + '\'';
if(multipleCurrencies)
qstring += ' and CurrencyIsoCode =\'' + theOpp.get('currencyIsoCode') + '\'';
// note that we are looking for the search string entered by the user in the name OR des cription
// modify this to search other fieldsif desired
if(searchString!=null)
{
qString+= ' and (Product2.Name like\'%' + searchString + '%\' or Product2.productcod e like \'%' + searchString + '%\')';
}
}
if(oppList.Product_Area__c=='Multiple')
{
qString = 'select Id, Pricebook2Id, IsActive, Product2.Name, Product2.Family, Product2.IsA ctive, Product2.Description, UnitPrice from Priceb ookEntry where IsActive=true and Product2.Product_ Group__c= \'' + sProductGroup + '\'and Pricebook2I d = \'' + theBook.Id + '\'';
if(multipleCurrencies)
qstring += ' and CurrencyIsoCode =\'' + theOpp.get('currencyIsoCode') + '\'';
// note that we are looking for the search string entered by the user in the name OR des cription
// modify this to search other fieldsif desired
if(searchString!=null)
{
qString+= ' and (Product2.Name like\'%' + searchString + '%\' or Product2.productcode like \'%' + searchString + '%\')';
}
}
if (objOpp.Product_Group__c!=null)
{
System.Debug('Product Group:'+ objOpp.Product_Group__c);
qString+= ' and (Product2.Product_Group__c like \'%' + objOpp.Product_Group__c + '%\')' ;
}
if (objOpp.Product_Area__c!=null)
{
System.Debug('Product Area :'+ objOpp.Product_Area__c);
qString+= ' and (Product2.Product_Area__c like \'%' + objOpp.Product_Area__c+ '%\')';
}
if (objOpp.Product_Family__c!=null)
{
System.Debug('Product Family:'+ objOpp.Product_Family__c);
qString+= ' and (Product2.Product_Family__c like \'%' + objOpp.Product_Family__c + '%\' )';
}
if (objOpp.Product_Family_Child__c!=null)
{
System.Debug('Product Family Child:'+objOpp.Product_Family_Child__c);
qString+= ' and (Product2.Product_Family_Child__c like \'%' + objOpp.Product_Family_Ch ild__c + '%\')';
}
Set<Id> selectedEntries = new Set<Id>();
for(opportunityLineItem d:shoppingCart)
{
selectedEntries.add(d.PricebookEntryId);
}
if(selectedEntries.size()>0){
String tempFilter = ' and Id not in (';
for(Id i : selectedEntries){
tempFilter+= '\'' + (String)i + '\',';
}
String extraFilter = tempFilter.substring(0,tempFilter.length()-1);
extraFilter+= ')';
qString+= extraFilter;
}
qString+= ' order by Product2.Name';
qString+= ' limit 101';
system.debug('qString:' +qString);
AvailableProducts = database.query(qString);
// We only display up to 100 results... ifthere are more than we let the user know (see vf page)
if(AvailableProducts.size()==101){
AvailableProducts.remove(100);
overLimit = true;
}
else{
overLimit=false;
}
}
Solved! Go to Solution.
Re: SObject row was retrieved via SOQL without querying the requested field
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-09-2012 10:51 PM
My Blog
Kiran
Re: SObject row was retrieved via SOQL without querying the requested field
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-09-2012 10:55 PM
My Blog
Kiran
Re: SObject row was retrieved via SOQL without querying the requested field
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-09-2012 11:10 PM
I have solved the issue. Instead of declaring object objOpp at beginning of the opportunityProductEntryExtension class controller, I have declared it after :
if(multipleCurrencies)
theOpp = database.query('select Id, Product_Group__c, Product_Area__c, Product_Family__c, Product_Family_Child__c, Pricebook2Id, Pricebook2.Name, CurrencyIsoCode from Opportunity where Id = \'' + controller.getRecord().Id + '\' limit 1');
else
theOpp = [select Id,Product_Group__c, Product_Area__c, Product_Family__c, Product_Family_Child__c, Pricebook2Id, PriceBook2.Name from Opportunity where Id = :controller.getRecord().Id limit 1];
objOpp= (Opportunity)theOpp;// this part is solved my problem.
Thanks for your response.
With Regards,
Mayank Pant

