Write a trigger to automatically create a related Contact whenever a new Account is created.
Answer
Basics: A trigger is Apex code that runs automatically before or after a record is inserted, updated, deleted or undeleted. To create a child Contact you need the parent Account's Id as Contact.AccountId. In a before insert trigger the Id is still null, so you use after insert. Records in Trigger.new are read-only in after context, which is fine here because you are creating different records, not editing the Account.
How it works: Salesforce passes up to 200 records per chunk in Trigger.new. You loop over them (no SOQL or DML inside the loop), add a new Contact to a list for each Account, then do a single DML after the loop. Best practice is one trigger per object that delegates to a handler class, so logic is testable and ordering is controlled.
Advanced / deep dive: Contact's only universally required field is LastName, but validation rules, required custom fields, duplicate rules, and triggers or flows on Contact all run on your inserted rows and can fail them. With plain insert, one bad row rolls back the whole Account save. With Database.insert(list, false) you get partial success and a SaveResult per row, so you can log failures without blocking Account creation; decide deliberately which behaviour the business wants. Duplicate rules: Apex DML runs duplicate rules; "Block" rules throw errors, "Allow with alert" is bypassed in Apex unless you set Database.DMLOptions.duplicateRuleHeader.allowSave = true. Recursion: this trigger does not re-fire itself, but a Contact trigger that updates Accounts could loop, so guard with a static Set<Id> of processed Ids rather than a single static Boolean (a Boolean wrongly skips later chunks of a 10,000-row load). Person Accounts auto-create a Contact, so exclude them if enabled. Declarative alternative: a record-triggered Flow (after save, Account created) with a Create Records element; Flow is preferred for simple cases, Apex for complex logic or very high volume. Workflow Rules and Process Builder are retired and cannot create records anymore for new automations.