• #28817
    Salesforce | Abhishek Abhishek #305
    Forcetalks

    How can I manipulate records with DML in Salesforce?

    How can I manipulate records with DML in Salesforce?

     

    #28821
    Salesforce | PRANAV PRANAV #659
    Forcetalks

    Hi Abhishek,
    Create and modify records in Salesforce by using the Data Manipulation Language, abbreviated as DML. DML provides a straightforward way to manage records by providing simple statements to insert, update, merge, delete, and restore records.

    For Example:
    // Create the account sObject
    Account acct = new Account(Name=’Acme’, Phone='(415)555-1212′, NumberOfEmployees=100);
    // Insert the account by using DML
    insert acct;

    You can practise it on Salesforce Trailhead under Manipulate Records with DML topic for better understanding.

    Hope this helps you.

    #28938
     William #11
    Forcetalks

    DML operations allow you to modify records one at a time or in batches. DML are the actions which are performed in order to perform insert, update, delete, upsert, delete & undelete.  You can perform DML operations either on a single sObject, or in bulk on a list of sObjects.

    Followings are DML actions

    •      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 Organization 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 up to 3 records to merge.

     

    Sample Code

    Account[] acctsList = [SELECT Id, Name, BillingCity

    FROM Account WHERE BillingCity = ‘Bombay’];

    for (Account a : acctsList) {

    a.BillingCity = ‘Mumbai’;

    }

    Account newAcct = new Account(Name = ‘Acme’, BillingCity = ‘San Francisco’);

    acctsList.add(newAcct);

    try {

    upsert acctsList;

    } catch (DmlException e) {

    System.debug(e.ErrorMessage());

    // Process exception here

    }

    #35826
    Salesforce | shariq shariq #1
    Forcetalks

    Hi,

    Manipulate Records with DML
    Use DML to insert, update, and delete records.
    Perform DML statements in bulk.
    Use upsert to either insert or update a record.
    Catch a DML Exception.
    Use a Database method to insert new records with the partial success option and process the results.
    Know when to use DML statements and when to use Database methods.

    Hope this helps.

Viewing 4 posts - 1 through 4 (of 4 total)

Please to reply to this topic.

CONTACT US

We're not around right now. But you can send us an email and we'll get back to you, asap.

Sending

About Us

Forcetalks is a Salesforce collaboration platform for coders & developers, geeks & nerds, consultants & business heads, admins & architects, managers & marketers and of course the business owners. A community where you can learn from, where you can contribute to. For you. For Salesforce. Read More...

Copyright 2018 Forcetalks. All Right Reserved.

Log in with your credentials

or    

Forgot your details?