+ Start a Discussion

Please help -controller extension

I have  a custom object Purchase Order which has a child object Purchase Order lines.
The purchase order lines have a Product lookup field(product__c) and a quantity  field(quantity__c).

Now i need to have  a list button "Create Prod Serials" on the purchase order lines which does the following:

1)First page:Displays the selected purchase order lines as a datatable displaying the product and the  input quantity field  (if the user wants to edit the quantity).This page has a button "Confirm".

2)When the "Confirm" button is clicked,
**the controller should first save the changes made,
**then for example the quantity is 2 on a line ,it should create 2 asset records for the product passing the product field value to the asset fields :name&product.
**display the newly created asset records as a data table with the product serial as input field.This  has a save button that saves the records

Iam a total newbie to controllers and though i have been reading on this ,its still very confusing and iam not able to execute this logic.

I tried by creating a custom list button "Create Serial No.s" on the purchase order lines which calls a visualforce page.
I created a simple visualforce page   that displays the selected purchase order line fields as a data table.

The visualforce page is as below:

<apex:page standardController="Purchase_Order_Line__c" >

    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockButtons location="Bottom"><apex:commandButton action="{!save}" value="Save"/>
            <apex:pageBlockTable value="{!selected}" var="line"  border="1">
    <td><apex:column value="{!line.name}" style="white-space:nowrap ;font-weight:bold"/></td>
        <apex:column />
   <apex:column value="{!line.Product__c}"/>
   <apex:column headerValue="Purchase Quantity">
   <apex:inputField value="{!line.Quantity__c}"/>


Now to achieve my logic i think i should use a controller extension that has the save ,create and display methods.

Public class myextension{

Page reference save(){


public create asset(){

public display asset(){


I tried writing some code but iam really struggling with the navigation ...

Please help me with this controller extension .i need to learn how to do this...


Take a look at this blog. It demonstrates how to write a Visualforce controller.


In the apex:page element define the extensions attribute. Then define an Apex class with this name.

Since the value attribute of pageBlockTable is defined as selected, in Apex class you will need to define a method getSelected.
            <apex:pageBlockTable value="{!selected}" var="line"  border="1">

The getSelected method will return an array of elements based upon SOQL results.