DML
===
DML is a series of statements and methods available in Aoex that enable a developer
to push data changes to the salesforce database.
insert
update
upsert
delete
undelete
merge
Insert
======
the insert statment saves a new record to the salesforce database.
After the insert is performed the Id field on the record is populated by the
system.
Contact con = new contact(lastName = 'Adnan', firstName='Mohammed');
[Link] = 'Safil';
[Link] = 'adnan@[Link]';
[Link](con);
//DEBUG|Contact:{LastName=Safil, FirstName=Mohammed, Email=adnan@[Link]}
insert con;
[Link](con);
//DEBUG|Contact:{LastName=Safil, FirstName=Mohammed, Email=adnan@[Link],
Id=0035j00001FqPp7AAF}
Update
======
The Update statement saves changes to an existing record to the database and the
record must have the Id field populated
List<Contact> con = [select firstName, lastName, email from contact where lastName
= 'Safil'];
[Link](con);
//DEBUG|(Contact:{FirstName=Mohammed, LastName=Safil, Email=adnan@[Link],
Id=0035j00001FqPp7AAF})
for(Contact c : con)
[Link] = 'adnan123@[Link]';
update con;
[Link](con);
//DEBUG|(Contact:{FirstName=Mohammed, LastName=Safil, Email=adnan123@[Link],
Id=0035j00001FqPp7AAF})
Upsert
======
The upsert statment is a combination of insert and update
List<Contact> conList = new List<Contact>();
//Insertion
Contact con1 = new Contact();
[Link] = 'Gopal';
[Link] = 'Aravind';
[Link] = '12345';
[Link](con1);
//Updation
List<Contact> conList2 = [Select lastName, firstName, phone from Contact where
lastName = 'Safil'];
for(Contact c : conList2){
[Link] = 'Safil1234';
[Link] = 'Khan';
[Link](c);
}
upsert conList;
[Link](conList);
//DEBUG|(Contact:{LastName=Safil1234, FirstName=Khan, Id=0035j00001FqPp7AAF},
Contact:{LastName=Gopal, FirstName=Aravind, Phone=12345, Id=0035j00001FqPI9AAN})
Delete
======
The delete statement removes a record with the given salesforce Id from the
database
List<Contact> conList = [Select lastName, firstName, email from Contact where
lastName = 'Safil1234'];
[Link](conList);
delete conList;
undelete
========
The undelete statement restores records from the recycle bin. These records must be
queried from the database.
List<Contact> conList = [Select lastName, firstName, email from Contact where
lastName = 'Safil1234' ALL ROWS];
undelete conList;
[Link](conList);
Merge
=====
The Merge statement merges upto 3 records into a single record and removes the
others
Contact newContact = new Contact(firstName = 'Paul', lastName = 'Battisson');
insert newContact;
Contact newContact2 = new Contact(firstName = 'Paul', lastName = 'Battisssson');
insert newContact2;
merge newContact newContact2;
//Output: firstName = 'Paul', lastName = 'Battisson')