+ Start a Discussion

update record in visualforce page table

how can i update a record in my visualforce page table?
my table is like this:
Name        UnitPrice(inputfields)            Link
Fuel1                  50.00                        Update Price
Fuel2                  60.00                        Update Price

this is my vf page:
<apex:page showHeader="false" sidebar="false" standardController="Fuel__c" extensions="FuelUpdateCX">
    <apex:form >
        <apex:messages />
        <apex:pageBlock >
            <apex:pageBlockTable value="{!Fuel}" var="f">
                <apex:column value="{!f.Name}"/>
                <apex:column headerValue="Unit Price">
                    <apex:inputField value="{!f.Unit_Price__c}"/>
                <apex:column width="10%">
                    <apex:commandLink action="{!updatePrice}" style="padding:1px 2px; font-weight:bold;">Update Price</apex:commandLink>

and this is the class:
public with sharing class FuelUpdateCX {
    public FuelUpdateCX(ApexPages.StandardController controller) {}
    public List<Fuel__c> getFuel() {
            return[select id, Name, Unit_Price__c from Fuel__c ORDER BY Name];
    public pageReference updatePrice() {
        //update fuel here
        return new PageReference('/apex/FuelUpdate');
should i use wrapper? how can i update the price here?
Add an Id parameter to your controller : public String SelectedFuelId {get;set;}

Then use the <apex:param tag

<apex:commandLink action="{!updatePrice}" style="padding:1px 2px; font-weight:bold;">
<apex:param name="SelectedFuelId"
Update Price</apex:commandLink>

Then update price is called, SelectedFuelId will be populated with the id of the fuel object you click the link of.
hi Elie. i tried it but didn't work. btw, i have a problem in the updatePrice method. the line update _getFuel or SelectedFuelId_. should i call the getFuel in this line? tnx for the help :)
You need to do another query that will do where Id=:SelectedFuelId

* You could replace SelectedFuelId by the complete object also to avoid having to query it again.
can you please check my updatePrice method? this is the updatePrice method:
public PageReference updatePrice() {
        Fuel__c newFuel = new Fuel__c();
        newFuel = [select id, name, Unit_Price__c from Fuel__c where id=:SelectedFuelId];
        update newFuel;
        return new PageReference('/apex/FuelUpdate');
what do you think the problem is?
You are not updating any value of the object.  You would need to do newFuel.Unit_Price__c = something before calling the update dml operation.