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
NecroGigglesNecroGiggles 

SObject row was retrieved via SOQL without querying the requested field

I have been playing around with a VF page and I can't figure out why i am getting this error the code saves fine. I did not write the code I am just trying to edit it. 

Here is the VF code  I underlined and bolded the code I added 


I have been playing around with a VF page and I can't figure out why i am getting this error the code saves fine. I did not write the code I am just trying to edit it.
 
 
<apex:page standardController="Opportunity" extensions="opportunityProductEntryExtension" action="{!priceBookCheck}" >
 
    <apex:sectionHeader Title="Manage {!$ObjectType.Product2.LabelPlural}" subtitle="{!opportunity.Name}"/>
    <apex:messages style="color:red"/>
 
    <style>
        .search{
            font-size:14pt;
            margin-right: 20px;   
        }
        .fyi{
            color:red;
            font-style:italic;
        }
        .label{
            margin-right:10px;
            font-weight:bold;
        }
    </style>
   
    <script type='text/javascript'>
   
        // This script assists the search bar functionality
        // It will execute a search only after the user has stopped typing for more than 1 second
        // To raise the time between when the user stops typing and the search, edit the following variable:
       
        var waitTime = 1;
       
   
        var countDown = waitTime+1;
        var started = false;
       
        function resetTimer(){
       
            countDown=waitTime+1;
           
            if(started==false){
                started=true;
                runCountDown();
            }
        }
       
        function runCountDown(){
       
            countDown--;
           
            if(countDown<=0){
                fetchResults();
                started=false;
            }
            else{
                window.setTimeout(runCountDown,1000);
            }
        }
   
    </script>
  
 
    <apex:form >
   
        <apex:outputPanel id="mainBody">
       
            <apex:outputLabel styleClass="label">PriceBook: </apex:outputLabel>
            <apex:outputText value="{!theBook.Name}"/>&nbsp;
            <apex:commandLink action="{!changePricebook}" value="change" immediate="true"/>
            <br/>
            <!-- not everyone is using multi-currency, so this section may or may not show -->
            <apex:outputPanel rendered="{!multipleCurrencies}">
                <apex:outputLabel styleClass="label">Currency: </apex:outputLabel>
                <apex:outputText value="{!chosenCurrency}"/>
                <br/>
            </apex:outputPanel>
            <br/>
           
<!-- this is the upper table... a.k.a. the "Shopping Cart"-->
 
            <!-- notice we use a lot of $ObjectType merge fields... I did that because if you have changed the labels of fields or objects it will reflect your own lingo -->
            <apex:pageBlock title="Selected {!$ObjectType.Product2.LabelPlural}" id="selected">
                      
                <apex:pageblockTable value="{!shoppingCart}" var="s">
                <apex:column >
                        <apex:commandLink value="Remove" action="{!removeFromShoppingCart}" reRender="selected,searchResults" immediate="true">
                            <!-- this param is how we send an argument to the controller, so it knows which row we clicked 'remove' on -->
                            <apex:param value="{!s.PriceBookEntryId}" assignTo="{!toUnselect}" name="toUnselect"/>
                        </apex:commandLink>
                    </apex:column>
                   
                    <apex:column headerValue="{!$ObjectType.Product2.LabelPlural}" value="{!s.PriceBookEntry.Product2.Name}"/>
                   
                    <apex:column headerValue="{!$ObjectType.OpportunityLineItem.Fields.Quantity.Label}">
                        <apex:inputField value="{!s.Quantity}" style="width:70px" required="true" onkeyup="refreshTotals();"/>
                    </apex:column>
                   
                      <apex:column headerValue="{!$ObjectType.OpportunityLineItem.Fields.Product_Type__c.label}">
                        <apex:inputField value="{!s.Product_Type__c}" style="width:70px" required="true" onkeyup="refreshTotals();"/>
                    </apex:column>
                   
                    <apex:column headerValue="{!$ObjectType.OpportunityLineItem.Fields.Terms__c.label}">
                        <apex:inputField value="{!s.Terms__c}" style="width:70px" required="true" onkeyup="refreshTotals();"/>
                    </apex:column>
                   
                    <apex:column headerValue="{!$ObjectType.OpportunityLineItem.Fields.Tearms_Legth__c.label}">
                        <apex:inputField value="{!s.Tearms_Legth__c}" style="width:70px" required="true" onkeyup="refreshTotals();"/>
                    </apex:column>
                  
                    <apex:column headerValue="{!$ObjectType.OpportunityLineItem.Fields.UnitPrice.Label}">
                        <apex:inputField value="{!s.UnitPrice}" style="width:70px" required="true" onkeyup="refreshTotals();"/>
                    </apex:column>
                   
                    <apex:column headerValue="{!$ObjectType.OpportunityLineItem.Fields.Description.Label}">
                        <apex:inputField value="{!s.Description}" required="false"/>
                    </apex:column>
                   
                </apex:pageblockTable>
           
           
                <apex:pageBlockButtons >
                    <apex:commandButton action="{!onSave}" value="Save"/>
                    <apex:commandButton action="{!onCancel}" value="Cancel" immediate="true"/>
                </apex:pageBlockButtons>
           
            </apex:pageBlock>
   
<!-- this is the lower table: search bar and search results -->
   
            <apex:pageBlock >
           
                <apex:outputPanel styleClass="search">
                    Search for {!$ObjectType.Product2.LabelPlural}:
                </apex:outputPanel>
 
                <apex:actionRegion renderRegionOnly="false" immediate="true">
               
                    <apex:actionFunction name="fetchResults" action="{!updateAvailableList}" reRender="searchResults" status="searchStatus"/>
                    
                    <!-- here we invoke the scripting to get out fancy 'no button' search bar to work -->
                    <apex:inputText value="{!searchString}" onkeydown="if(event.keyCode==13){this.blur();}else{resetTimer();}" style="width:300px"/>
                    &nbsp;&nbsp;
                    <i>
                        <!-- actionStatus component makes it easy to let the user know when a search is underway -->
                        <apex:actionStatus id="searchStatus" startText="searching..." stopText=" "/>
                    </i>
                   
                </apex:actionRegion>
           
                <br/>
                <br/>
           
                <apex:outputPanel id="searchResults">
               
                    <apex:pageBlockTable value="{!AvailableProducts}" var="a">
                   
                        <apex:column headerValue="{!$ObjectType.Product2.Fields.Name.Label}" value="{!a.Product2.Name}" />
                       
                        <apex:column headerValue="{!$ObjectType.Product2.Fields.Family.Label}" value="{!a.Product2.Family}"/>
                       
                        <apex:column headerValue="{!$ObjectType.Product2.Fields.Description.Label}" value="{!a.Product2.Description}"/>

                       
                         <apex:column headerValue="{!$ObjectType.Product2.Fields.Product_Type__c.Label}" value="{!a.Product2.Product_Type__c}"/>
                       
                        <apex:column headerValue="{!$ObjectType.Product2.Fields.Terms__c.Label}" value="{!a.Product2.Terms__c}"/>
                       
                        <apex:column >
                            <!-- command button in a column... neato -->
                            <apex:commandButton value="Select" action="{!addToShoppingCart}" reRender="selected,searchResults" immediate="true">
                                <!-- again we use apex:param to be able to tell the controller which row we are working with -->
                                <apex:param value="{!a.Id}" assignTo="{!toSelect}" name="toSelect"/>
                            </apex:commandButton>
                        </apex:column>
                       
                    </apex:pageBlockTable>
                   
                    <!-- We put up a warning if results exceed 100 rows -->
                    <apex:outputPanel styleClass="fyi" rendered="{!overLimit}">
                        <br/>
                        Your search returned over 100 results, use a more specific search string if you do not see the desired {!$ObjectType.Product2.Label}.
                        <br/>
                    </apex:outputPanel>
                    
                </apex:outputPanel>
           
            </apex:pageBlock>
           
        </apex:outputPanel>
 
    </apex:form>
 
</apex:page>
 
Best Answer chosen by NecroGiggles
Waqar Hussain SFWaqar Hussain SF
Look at this link, it really helps you.
https://help.salesforce.com/apex/HTViewSolution?id=000170999&language=en_US

All Answers

Balaji Chowdary GarapatiBalaji Chowdary Garapati

Did you add Family & Description to the SOQL that was pulling the information of  "Product2" records while bieng added to AvailableProducts?


Thanks,
Balaji

Waqar Hussain SFWaqar Hussain SF
Look at this link, it really helps you.
https://help.salesforce.com/apex/HTViewSolution?id=000170999&language=en_US
This was selected as the best answer
NecroGigglesNecroGiggles
Thanks Got it