In this blog we are going to learn about DML(Data Manipulation Language) operations in Salesforce. Following types of DML statements are available in salesforce.

  • insert : Use this statement to create the records of sObject.
  • update : Use this statement to update the existing records of sObject.
  • upsert: Use this statement to create the new record or update the existing records on the basis of  Id or external field.
  • delete : Use this statement to delete the existing record
  • undelete : Use this statement to restore the records from Organisation recycle bin.
  • merge : Use this statement to merge the records of same sObject type by deleting other and re-parenting the related records. You can use upto 3 records to merge.

DML Example

Let’s do some example of above statements. To execute the below mentioned example GOTO||Developer Console||Debug||Open Execute Anonymous Window.

  1. Insert Operation:
    //Create new contact by using insert operation
    Contact con = new Contact(FirstName = 'Jon',Salutation='Mr.' LastName='Doe', Phone ='9838783737');
    insert con;

  2. Update Operation:
    //Update existing contact by using update operation
    Contact cont = [SELECT Id FROM Contact WHERE FirstName = 'Jon' Limit 1];
    cont.Birthdate = Date.parse('12/3/1994');
    update cont;

  3. Upsert Operation:
    //Create or Update contact by using upsert operation
    Contact cont = [SELECT Id FROM Contact WHERE FirstName = 'Jon' Limit 1];
    cont.Birthdate = Date.parse('11/3/1994');
    upsert cont;

  4. Delete Operation:
    //Delete existing contact by using delete operation
    Contact con = new Contact(FirstName = 'Jon',Salutation='Mr.' LastName='Doe', Phone ='9838783737');
    delete con;

  5. Undelete Operation:
    //Undelete existing contact by using undelete operation
    Contact cont = [SELECT Id FROM Contact WHERE FirstName = 'Jon' ALL ROWS];
    undelete cont;

  6. Merge Operation:
    //Merge  contact by using merge operation
    Contact con = new Contact(FirstName = 'Jon',Salutation='Mr.' LastName='Doe', Phone ='9838783737');
    insert con;

 

Support

That’s all about DML operation in salesforce, still if you have any further query, feel free to contact us, we will be happy to help you
https://wedgecommerce.com/contact-us/

Leave A Reply

Please verify that you are not a robot.

Tell us about Your Company

How can we help you with your business?




    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home