Site icon WedgeCommerce

DML Operation In Salesforce

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.

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/

Exit mobile version