⚡ Code it · 50 XP
Hello, Apex
Your first DML
Apex is Salesforce's server-side language. It looks a lot like Java, but it runs inside your org, right next to your data.
Records are just objects. You create one with new, then save it with a DML statement:
Contact c = new Contact(LastName = 'Nguyen');
insert c;
System.debug(c.Id); // the Id is filled in after insert
A few things to notice:
- Statements end with
;and strings use single quotes - You can set fields in the constructor:
new Contact(LastName = 'Nguyen', Email = 'n@example.com') System.debug(...)prints to the debug log, which shows up in the console under the editor
Your mission
- Create an
Accountnamed Quill the Raccoon insertitSystem.debugitsId
Use Run to try it, then Submit when you're happy.
🦝 Relax, everything you run here is rolled back afterwards, so your org stays clean.