How can we Insert, Update and Delete a record in a Visualforce Page ?

We can do simple Insert, Update and Delete in a Visualforce Page with out using any APEX code. If you want extend the standard methods, you will need to write an extension to the Standard Controller or create a Custom Controller.

Simple INSERT, UPDATE, DELETE in Visualforce page:

We can insert, update and delete records by  using Salesforce standard controller methods like “Save” and “Delete”.

For example we want to create, update or delete an account record using standard methods using below code:

Visualforce Code:


We did not write any class and methods to perform DML operations on objects. Now let’s test the page using following URL:



Update & Delete


Extending standard controller methods using extension class

Let’s now extend standard controller save() method by amending previous code:


Create the following exctension class and override standard ‘save’ method.

Apex Code:

public class Blog_AccountExtension {
    Account acc;
    public Blog_AccountExtension(Apexpages.StandardController ctrl){
        //get account record
        acc = (Account)ctrl.getRecord();
    public PageReference Save(){
        //do your custom changes here and save
        acc.Name = 'TEST Account';
        //do insert new or update
        upsert acc; 
        return new PageReference('/'+acc.Id);



Salesforce provides standard methods to perform DML operations on the sObjects. We can always override these standard methods by writings extension classes.


Senior Salesforce Architect
In Connect me on LinkedIn
twitter Follow me on Twitter @apexcoder
blogger Subscribe to my blog
email Email me

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s