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
Sami ShakithSami Shakith 

Error: Compile Error: Initial term of field expression must be a concrete SObject: List<Price_Details__c> at line 48 column 17

Hi,

I am trying to develop a project for my learning purpose. I have created a two VF page and a controller class.

My Quote VF page
<apex:page standardcontroller="Opportunity" extensions="QuoteController" sidebar="false" > 
  <apex:form > 
  <apex:pageBlock > 
  <html>
  <body>
  <table>
  <tr>
  <apex:pageBlockSection > 
  
  <td><table border="0" bgcolor="#00BFFF" >
  <tr><apex:inputField value="{!SearchCriteria.Operating_Model__c}"/></tr>
    <tr><apex:inputText label="Quantity" value="{!Quantity}"/> </tr>

<apex:inputField value="{!SearchCriteria.partno__r.Type__c}" id="degreeLevel" onchange="assignDegreeLevel(this.value)"/>       


 <apex:actionFunction name="assignDegreeLevel" action="{!filterApplicant}" 
   reRender="program" immediate="true">
      <apex:param name="degreeSelected" assignTo="{!degreeSelected}" value=""/>
 </apex:actionFunction> 
  <tr><apex:commandButton value="Go" action="{!filterApplicant}"/> </tr>
  </table>
  </td>
    </apex:pageBlockSection> 
    <apex:pageBlockSection rendered="{!GoShopping}">
      <apex:commandLink action="{!GoToCart}" value="Go to Shopping Cart"/><br></br><br></br>
      <apex:outputLink value="/?id={!Opportunity.id}">Go Back</apex:outputLink>
    </apex:pageBlockSection>
      <td style="width:100%"><apex:pageBlockTable value="{!FilteredApplicants}" var="applicant"> 
          <apex:column >
            <apex:inputCheckbox value="{!selected}"/>      
          </apex:column>
          <apex:column value="{!applicant.Operating_Model__c}"/>
          <apex:column value="{!applicant.MSRP__c}"/>
          <apex:column value="{!applicant.Buying_Price__c}"/> 
          <apex:column value="{!applicant.Type__c}"/>
      </apex:pageBlockTable> 
      <apex:pageMessages id="error"></apex:pageMessages> 
      </td></tr>
      </table>
      </body>
      </html>
  </apex:pageBlock> 
   </apex:form> 
</apex:page>
My QuoteController class
public with sharing class QuoteController { 
public boolean GoShopping{get;set;}
public boolean GoToCart{get;set;}
public boolean Selected{get;set;}
public Integer Quantity{get;set;}
public String degreeSelected{get;set;}
public decimal NetAmount{get;set;}
public decimal NetAmount1{get;set;}
public Opportunity opp{get;set;}
public List<Parts__c> types{get;set;}   
public List<Price_details__c> FilteredApplicants{get;set;}  
public list<Price_details__c> listPrice{get;set;}
public Price_details__c SearchCriteria{get;set;} 
public String cid= ApexPages.currentPage().getParameters().get('id');
public QuoteController(ApexPages.StandardController controller) 
 { 
   
   SearchCriteria = new Price_details__c(); 
   types = new list<Parts__c>();
   types=[select type__c from parts__c];
   GoShopping = false; 
   NetAmount=0;
     
 } 
   public void filterApplicant()     
    { 
        FilteredApplicants = new List<Price_details__c>(); 
        FilteredApplicants = [SELECT Id, Name, Region__c, MSRP__c, Operating_Model__c, Buying_Price__c, QuantityStart__c,QuantityEnd__c,Type__c 
        FROM Price_details__c WHERE Operating_Model__c =: SearchCriteria.Operating_Model__c and QuantityStart__c<=:Quantity 
        and QuantityEnd__c>=:Quantity AND  Type__c=:degreeSelected];
        GoShopping=true;
      
if(FilteredApplicants.size() == 0) 
      { 
      Apexpages.addMessage(new ApexPages.Message

(ApexPages.Severity.INFO,''+'No records to Display'));  
     } 
    } 
public PageReference GoToCart()
{
        Opp = new Opportunity();
        listPrice = new list<Price_Details__c>();
        listPrice = [select id, name, Buying_Price__c from price_details__c];
        for(Price_details__c price: listPrice)
        {
            if(selected=true){
                listPrice.Opportunity__c=Opp.Name;
                NetAmount=NetAmount+price.Buying_Price__c;
                netAmount1=NetAmount;
                system.debug('@@@@@'+NetAmount);
                }
         }
    pagereference ref;
    ref = new pagereference('/apex/ShoppingCart?id='+cid);
    ref.setredirect(true);
    return ref;
    }
    
}
ShoppingCart VF page
<apex:page StandardController="Opportunity" extensions="QuoteController">
  <apex:form > 
      <apex:pageBlock >
          <apex:pageBlockSection columns="1">
              <apex:outputField label="User Name" value="{!opportunity.Name}"/>
              <apex:outputField label=" Account Name" value="{!Opportunity.AccountId}"/>
              <apex:outputField label="Email Id" value="{!Opportunity.Email__c}"/>
              <apex:outputLabel value="{!NetAmount}"></apex:outputLabel>
          </apex:pageBlockSection>
          
      </apex:pageBlock>
  </apex:form>
         Related price details for {!Opportunity.name}:    
          <apex:relatedList list="Price_Details__r" />
          
</apex:page>

While saving this class it shows the error like this

Error: Compile Error: Initial term of field expression must be a concrete SObject: List<Price_Details__c> at line 48 column 17.

Please I need someone help. 

 
Jason HardyJason Hardy
You're trying to fill in a string to an ID field. Adjusted this line
listPrice.Opportunity__c=Opp.Name;
to this
listPrice.Opportunity__c=Opp.id;
That should resolve your problem.

 
Jason HardyJason Hardy
Also, I'm running on the assumption that you're setting a concrete opportunity. With what you're using right now, there won't be an ID defined. You can either query or set the id from the controller.
Sami ShakithSami Shakith
Thanks for your reply jason.

But showing the same error. What shall i do?
Akshat Agrawal SFCAkshat Agrawal SFC

listPrice is list .

 listprice[0].Opportunity__c=Opp.id; 

Jason HardyJason Hardy
Sorry missed that, you're trying to set a list value, not the iterated value. Here is your loop definition:
Price_details__c price: listPrice
"price" is the current iteration of the "listPrice" list. In your current setup, you're trying to say list.field = thisValue.
You'll need to do this:
price.Opportunity__c=Opp.id;
Akshat Agrawal SFCAkshat Agrawal SFC

price.Opportunity__c=Opp.id;  is correct

Sami ShakithSami Shakith
1st Vf page will show one sidebar. In that give the details for serch criteria. After clicking go, list of record will be shown in right side. I gave one check box for all the record. i can choose multiple records for a single opportunity. Once i click Go To Shopping cart link it should add the all buying price of selected records and the record opportunity name will be updated with the opportunity name. Thats it. 

In that i am facing 3 problems.

1st is it shows error while saving the class.
2nd is if i command that line and continue to save, its saved but the NetAmount is just adding single record.
3rd is even that single NetAmount value not displaying while redirecting for 2nd page.

Please give some solution. What mistakes i did in that.
Sami ShakithSami Shakith
Now no error while saving. But it is not updating the opportunity name and not add the values for NetAmount
Akshat Agrawal SFCAkshat Agrawal SFC
for(Price_details__c price: listPrice)

        {

            if(selected=true){

                price.Opportunity__c=Opp.id;

                NetAmount=NetAmount+price.Buying_Price__c;

                netAmount1=NetAmount;

               system.debug('@@@@@'+NetAmount);

                }
        

         }
    Update listprice;

    pagereference ref;

    ref = new pagereference('/apex/ShoppingCart?id='+cid);

    ref.setredirect(false);

    return ref;

    }

update and set redirect
Sami ShakithSami Shakith
Thanks Akshat Agrawal.

But this to has some problems. All the product detail records is adding as a line item for opportunity. And i am not getting the net amount.
Sami ShakithSami Shakith
That mistake is in IF condition. It getting all the records in the object. How to change that declaration? Please tell me.
Akshat Agrawal SFCAkshat Agrawal SFC

You are not binding checkbox with records.

 

https://developer.salesforce.com/page/Wrapper_Class

If this answer helps you  please mark it as best answer. 

Sami ShakithSami Shakith

Hi Akshat , 

Thanks for your solution.

I tried in seperated VF page its worked. But combine the code in class its showing error. 
public class EpartsController{
public Integer Quantity{get;set;}
public Boolean GoToCart{get;set;}
public Boolean HyperLink{get;set;}
public Price_details__c SearchCriteria{get;set;}
public List<Price_Details__c> selectedList{get;set;}
public List<wrapPrice> wrapPriceList{get;set;}
public opportunity opp{get;set;}
public String cid = ApexPages.currentPage().getParameters().get('id');
public EpartsController(ApexPages.StandardController controller) 
 { 
   SearchCriteria = new Price_details__c();
   HyperLink=false; 
 } 
public void go(){
if(wrapPriceList == null) {
            wrapPriceList = new List<wrapPrice>();
                for(Price_Details__c pd: [SELECT Id, Name, Region__c, MSRP__c, Operating_Model__c, Buying_Price__c, QuantityStart__c,QuantityEnd__c,Type__c 
        FROM Price_details__c WHERE Operating_Model__c =: SearchCriteria.Operating_Model__c and QuantityStart__c<=:Quantity 
        and QuantityEnd__c>=:Quantity]) {
                    wrapPriceList.add(new wrapPrice(pd));
}
HyperLink=true;
}
}
public pagereference GoToCart{
    opp=new opportunity();
    opp=[select id, name, NetAmount__c from opportunity where id=:cid];
    selectedList = new List<Price_Details__c>();
    NetAmount=0; 
        for(wrapPrice wrapPriceObj : wrapPriceList) {
            if(wrapPriceObj.selected == true) {
                wrapPriceObj.Opportunity=opp.id;
                NetAmount=NetAmount+wrapPriceObj.pds.Buying_Price__c;               
            }
        }
        opp.NetAmount__c=NetAmount;
        update opp;
        update wrapPriceObj;
        pagereference ref;
        ref = new pagereference('/apex/ShoppingCart?id='+cid);
        ref.setredirect(true);
        return ref;
}
public class wrapPrice {
        public Price_Details__c pds {get; set;}
        public Boolean selected {get; set;}
 
        public wrapPrice(Price_Details__c pd) {
        pds = pd;
        selected = false;
        }
}
}


Error: Compile Error: unexpected token: 'opportunity' at line 26 column 7

While saving it shows like this. Please tell me what should i do.