Compile error:Invalid type: ApexPages.StandardController 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 >
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.StandardController 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.StandardController at line 4 column 27.
Can somebody please help me? iam really stuck here badly....
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.
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.
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
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.
Thank you! This worked!