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
emuelasemuelas 

Compile error:Invalid type: ApexPages.StandardControlle​r at line 4 ....

Hi ,
I have  a custom object Purchase_Order__c which has a child object Purchase_order_line__c.
Now i have a page button on the Purchase_Order "Receive" which calls a visualforce page that displays the related purchase_order_lines as a table with the received quantity as input fields.There is also a "Save" Button.
But when i make changes and click on the save button the changes are not saved.

This is because the id passed to the page is the purchase_order id and nopt the related list.My code was as below:
<apex:page standardController="Purchase_Order__c">
    <apex:form >
            <apex:pageBlock >
      
       
            <apex:pageBlockButtons location="bottom">
                <apex:commandButton action="{!save}" value="Save"/>
            </apex:pageBlockButtons>
            <apex:pageBlockTable value="{!Purchase_Order__c.Purchase_Order_Lines__r}" var="line"  border="1">
            <tr>
<td><apex:column value="{!line.name}" style="white-space:nowrap ;font-weight:bold"/></td>
</tr>
<apex:column />
<apex:column value="{!line.Product__c}"/>
<apex:column headerValue="Purchase Quantity">
   <apex:outputField value="{!line.Quantity__c}"/>
       </apex:column>
         <apex:column headerValue="Received Quantity">
   <apex:inputField value="{!line.Received_Quantity__c}"/>
       </apex:column>
             <apex:column headerValue="RMA Quantity">
   <apex:inputField value="{!line.RMA_Quantity__c}"/>
       </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Now to resolve this i tried to write a controller extension  for purchase_order to update the records when save is clicked:


public class receiveController {
 
  // Constructor
 public receiveController(ApexPages.StandardControlle​r controller) {
  this.po = (Purchase_order__c)controller.getRecord();          
    
 
     this.pol = [ SELECT
       d.Name, d.quantity__c
            FROM
      purchase_order_line__c d
      WHERE
      d.purchase_order__c = :po.id ];
 }
 
 // Action Method called from page button
 public pagereference saveChanges() {
  upsert this.pol;
  return null;
 }
 
 // Action Method called from page link
 public pagereference newRec() {
  Purchase_order_line__c d = new Purchase_order_line__c();
  d.Purchase_order__c =this.po.id;
 pol.add( d );
  return null;
 }
 
 // public Getter to provide table headers
 public string[] getheaders() { return new string []
  {'Name','Quantity__c'} ; }
 
 // public Getter to list
 public Purchase_order_line__c[] getRecs() {
  return this.pol;
 }
 
 // class variables
Purchase_order__c po;
Purchase_order_line__c[] pol;
}


But i get a compile error:

Error: Compile Error: Invalid type: ApexPages.StandardControlle​r at line 4 column 27.

 

Can somebody please help me? iam really stuck here badly....

Best Answer chosen by Admin (Salesforce Developers) 
ngabraningabrani

Couple of things to explore -
1. In line 4 of Apex rename the local variable from controller to something else like stdController. Just in case controller is a reserved word.

2. In the Visualforce page element, add the extension attribute
<apex:page standardController="Purchase_Order__c" extensions="receiveController">
This will not solve the compilation error in Apex though.

All Answers

ngabraningabrani

Couple of things to explore -
1. In line 4 of Apex rename the local variable from controller to something else like stdController. Just in case controller is a reserved word.

2. In the Visualforce page element, add the extension attribute
<apex:page standardController="Purchase_Order__c" extensions="receiveController">
This will not solve the compilation error in Apex though.

This was selected as the best answer
emuelasemuelas

Thank you! This worked!