The full form of DML is Data Manipulation Language and through DML Statements we can implement DML operations in the salesforce. DML is essential in Apex, as every business requires some changes and modifications regularly. Database Methods are the system methods that are also used to carry out DML operations. Database methods are more flexible than DML statements. The data manipulation operations like insertion, deletion, and updation are supported in Salesforce. The DML operations are implemented in the following way:
Want to enhance your skills in dealing with the world's best CRM, enroll in our Salesforce Training |
The DML insert operation is used to establish new data in the database. The data is added for any custom or standard object.
Example:
Student newStud= new Student(Stud_Name=’Rakesh’);
Try {
Insert newStud;
} catch(DmlException d) {
Exception Code
}
The above code tells us how to insert a new student name. The try-and-catch block is used to check whether a student with name Rakesh is already present in the database or not.
The delete operation is used to delete the existing records of a standard object or a custom object. The records can be anything like Student details, employee details, etc. An example for this deletion operation is as follows:
Student[] OldStuds= [SELECT Stud_ID , Stud_Name FROM Student WHERE Stud_Fee<10000];
Try{
Delete OldStuds;
} catch (DmlException d) {
Exception Code
}
The above code deletes the records of the students who have fees lesser than 10000.
This DML operation updates or modifies the existing records of a standard object or a custom object. The following example shows how we can update an existing record:
Student s = new Student(Name=” Rakesh”)
insert(s)
Student myStud = [ SELECT Stud_ID, Stud_Name, Stud_Fee FROM Student WHERE Stud_ID= s.Stud_ID];
myStud.Fee=’10000’;
try{
Update myStud;
} catch (DmlException d) {
Exception Code
}
This DML operation is used to update the existing record and creates a new record in a single statement.
Example:
Upsert vobject[optional_field]
Upsert vobject[] [optional_field}
The upsert statement suits the sObjects with available records by equating values of one domain. While invoking the Upsert statement if we don’t mention the domain it uses the ID of the sObject to compare the sObject with the available records in the salesforce. If you specify the ID, you can use it for comparing.
For custom objects, we should mention a custom field labelled as external ID. For Standard objects, we have to mention a field which has the idLookup attribute determined to be true.
Checkout Salesforce Interview Questions
This DML operation is used to restore the existing records of a standard object or a custom object.
Syntax
Undelete vObject | Name
This DML Operation is used to merge three records of the same object into one record. Merge operation is used to combine the records.
Syntax:
Merge vObject vObject
Merge vObject ID
The first argument portrays the superior record to which the other records are merged. The second argument portrays one or two records that are to be merged and after that, they can be deleted.
Conclusion
In salesforce, DML operations are performed to change the data according to our requirements. Dml operations play a key role in handling and formatting the data. DML plays a key role in Apex as it deals with crucial operations of the database.
In the next topic, we will discuss in detail about “Governor Limits in Salesforce”. Keep following us for more info on Salesforce Development / Programming.
Are you looking to get trained on Salesforce, we have the right course designed according to your needs. Our expert trainers help you gain the essential knowledge required for the latest industry needs. Join our Salesforce Certification Training program from your nearest city.
Salesforce Training Chennai, Salesforce Training Dallas, Salesforce Training Bangalore, Salesforce Training Hyderabad, Salesforce Training Mumbai, Salesforce Training Delhi, Salesforce Training Noida, Salesforce Training New York, Salesforce Training Chicago, Salesforce Training Kolkata, Salesforce Training Gurgaon, Salesforce Training Pune.
These courses are equipped with Live Instructor-Led Training, Industry Use cases, and hands-on live projects. Additionally, you get access to Free Mock Interviews, Job and Certification Assistance by Certified Salesforce Trainers
Mindmajix offers different Salesforce certification training according to your desire with hands-on experience on Salesforce concepts
Our work-support plans provide precise options as per your project tasks. Whether you are a newbie or an experienced professional seeking assistance in completing project tasks, we are here with the following plans to meet your custom needs:
Name | Dates | |
---|---|---|
Salesforce Training | Dec 21 to Jan 05 | View Details |
Salesforce Training | Dec 24 to Jan 08 | View Details |
Salesforce Training | Dec 28 to Jan 12 | View Details |
Salesforce Training | Dec 31 to Jan 15 | View Details |
Arogyalokesh is a Technical Content Writer and manages content creation on various IT platforms at Mindmajix. He is dedicated to creating useful and engaging content on Salesforce, Blockchain, Docker, SQL Server, Tangle, Jira, and few other technologies. Get in touch with him on LinkedIn and Twitter.