What is DML? How different is it from SOQL Actions?

This question is designated as a community wiki, please add your inputs, guides (please try to ignore oustside links, and bring the important skimmed data in here.

  • What is DML?

  • What is Dynamic-DML?

  • How are they different from SOQL actions?


Fundamentally DML (Data Manipulation Language) and SOQL (Salesforce Object Query Language) are different in that one creates, updates and deletes data (DML) and the other reads it (SOQL). You will also encounter SOSL (Salesforce Object Search Language), this is another way to read data using advanced search criteria.

Literal Usage. Both support the ability to express literally in your code the objects and fields you want to reference and the platform ensures at the time you upload / save your code these exist. Which on the whole is recommended, as Salesforce will also help ensure that if you attempt to change such objects or fields you are notified of other references in your code.

SOQL example…

List aa = [SELECT Id, Name FROM Account WHERE Name = ‘Acme’];

DML example…

insert new Account(Name = ‘Singha’);

Dynamic Usage. In contrast to Dynamic DML and for that matter Dynamic SOQL, where by you can perform the same operations by referencing the fields at runtime using SOQL query strings dynamically constructed or using methods on the SObject class to dynamically set or get field values. This can be a very powerful feature for building applications that need to sense more about the customers own configuration and objects, but requires more advanced thinking and testing.

Dynamic SOQL example…

SObject s = Database.query(‘SELECT Id FROM account LIMIT 1’)

Dynamic DML example…

Object o = s.get(‘AccountNumber’);

s.put(‘AccountNumber’, ‘abc’);

update s;

You can read more about these topics in the following links.

Source : Link , Question Author : Saariko , Answer Author : Community

Leave a Comment