How to update particular record in Visualforce page

Updating records on Visualforce Page

It is easy to use point and click to update records in Salesforce. A record can be updated by clicking the record Name link and then click the Edit button on the Edit page which takes you to the Detail page where you perform the necessary update and then Save or clicking the Edit button directly on the list view page which takes you to Detail page where the necessary actions are performed.                                                                      

It is also possible to use Standard Controller and its methods like save, cancel, delete and edit on a Visualforce code. However, there are occasions when you need to write a custom controller to perform updating functionality according to your given Use Case.

In this post, the requirement is to be able to update a particular record from a list of records on the Visualforce page using a custom controller whereby there will be an Update link for each record on the Visualforce page.

For the Visualforce Code:

Check that I did not use the title attribute of <apex:pageBlock> but the <h2> tag for the page title because I wanted to center it and also increase the font size.

The Controller:

Below is output for the above codes

 By updating any of the editable fields, each record can be updated individually.

Note that the same code can be used to save or update the entire page records using an update button for the entire page. To do this, comment out the update link column in the Visualforce code and add the code below between the <apex:pageBlockTable> end tag and </apex:pageBlock> :

The output will now look like this one below

This Post Has One Comment

  1. Thanks for the code it helped alot

Leave a Reply

Close Menu