Experience Salesforce
Insert | APEX DML Standalone Statements
What You’ll Learn
- Apex Insert
Topics
- What Is DML In Salesforce?
- Insert | APEX DML Standalone Statements
- Update | APEX DML Standalone Statements
- Upsert | APEX DML Standalone Statements
- Delete | Apex DML Standalone Statement
- Undelete | Apex DML Standalone Statement
- Merge | APEX DML Standalone Statements
- APEX DML Statements Best Practices
- Database Class in APEX
- Empty Recycle Bin
- Count Query | Method in Apex Database Class
- Lead Conversion | Method in Apex Database Class
- Transaction Control and Rollback
- Database Class Method Result Object
To create a new record, you need to use the Insert statement.
public static void main() {
Account a = new Account(name = ’Shubham’, numberOfEmployees = 150);
insert a;
}
Example 2:
List < Contact > newConList = new List < Contact > ();
List < Contact > conList = [SELECT firstname, lastname FROM Contact];
for (Contact cc: conList) {
Contact c1 = new Contact(lastname = cc.lastname, firstname = cc.firstname);
insert c1; // too many DML statements, hence Limit Reached
}
for (Contact cc: conList) {
Contact c1 = new Contact(lastname = cc.lastname, firstname = cc.firstname);
newConList.add(c1);
}
insert newConList; // only 1 DML Statement
Account a = [SELECT Name FROM Account WHERE Name like‘ sh % ’LIMIT 1];
Contact c = new Contact(lastName = ’Again’, AccountId = a.id);
insert c;
Next Topic
Need Extra Support? Our FREE study materials have got you covered.
Our expert-prepared study materials provide the answers you need. Clear your doubts and improve your skills with detailed notes from industry professionals.