Creating, Reading, Updating, And Deleting Records In Salesforce Apex (CRUD Operation In Salesforce)


If we want to save records in the database on a permanent basis, we use DML statements in salesforce. We have multiple DML statements through which we can insert, update, delete or undelete records in the Salesforce database.

Some are mentioned below:

1. Insert

2. Delete

3. Update

4. Undelete

INSERT Operation

It is used to insert new records into any object. In this, row identification is not required due to the insertion of records.


DMLStatement sObjectName;

Insert sObjectName;


Here I want to insert Account record with Account name as ‘New Account’ and Industry as chemical.

Account acc = new Account();

acc.Name = ‘New Account’;

acc.Industry = ‘Chemicals’;

insert acc;

UPDATE Operation

It is used to modify the existing data or records. Row identification is required since we are updating the records. So, we need to identify which record to update.


Update sObjectName;


Update the type to ‘prospect’ and Industry as ‘Banking’ of the Account object.

acc.type = ‘Prospect’;

acc.Industry = ‘Banking’;

update acc;

DELETE Operation

It is used to delete the existing records present in our salesforce org.

Once the record is deleted, it will go to recycle bin for 15 days. Within 15 days, we can restore our records, after that, they will be no more present in our org.


delete sObjectName;


delete acc;

The record will be deleted and stored in the recycle bin.



  • Barry Allen

    A Full Stack Developer with 10+ years of experience in different domain including SAP, Blockchain, AI and Web Development.

    View all posts


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.