function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Explanation on DML needed to persist a record

I'm new to coding. On, it says "creating an sObject doesn’t persist it as a record in the database. To save the sObject as a record, and do other things with it, you’ll need to use DML." I'm trying to understanding why and whether this is something specific to sObject (i.e. SFDC), or is this common with other programming languages too?
Best Answer chosen by szesze21
Jithin Krishnan 2Jithin Krishnan 2
The statement means that when you create an SObject in Apex using the below syntax (where values is the corresponding field values),
SObject sobjectname=new SObject(values);
 you are not actually creating a record. Only when you perform DML operations like insert, delete update etc the record gets actually created.
insert sobjectname;
Consider java programming. Its similar to creating an object that you want to insert into database. You create the object, assign values to it and the data gets inserted only when you use DML statements to insert it by establishing a JDBC connection. Here, you don't have to establish any connection to the database. A statement like 'insert sobjectname;' will insert the values in the database.

Please let me know if you have any doubts.