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 

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:pageBlockButtons>
            <apex:pageBlockTable value="{!selected}" 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:inputField value="{!line.Quantity__c}"/>
   </apex:column>             
            </apex:pageBlockTable>
        </apex:pageBlock>

    </apex:form>
</apex:page>



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...

ngabraningabrani

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

http://astreait.com/wordpress/?p=3

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.