Chapter 127% of the exam50 min
Developer Fundamentals
How Salesforce's multitenant platform shapes the code you write, where the model, view and controller live, when to choose clicks over code, how to model data your code can rely on, and what Agentforce for Developers can and can't do for you.
By the end of this chapter you can
- Explain why a multitenant platform enforces governor limits, and write code that stays inside them
- Place Salesforce features in the model, view and controller layers, and choose between Visualforce and Lightning components
- Choose between a formula field, a roll-up summary, a flow and Apex for a requirement
- Design objects, relationships and external IDs that code can query and load reliably
- Use Agentforce for Developers (now the Agentforce Vibes extension) well, and know its limitations
Multitenancy and governor limits
Salesforce is a multitenant platform. Thousands of companies (tenants) run on the same servers, the same database and the same code, and Salesforce upgrades all of them together three times a year (the Spring, Summer and Winter releases). Each org's data and customisations stay private to it, but the computing power underneath is shared.
Your objects, fields, flows and Apex are metadata: descriptions that the platform reads and runs. Because you never touch the underlying servers or database directly, your customisations keep working when Salesforce upgrades the platform underneath them.
Why limits exist
If one org's code could run for an hour or read millions of rows in one request, every other org on the same servers would slow down. So the Apex runtime enforces governor limits: hard ceilings on what a single transaction can do. A transaction is everything that runs as a result of one request: a trigger, the flows and validation rules it causes, and any other triggers those fire, all count against the same limits.
| Limit per transaction | Synchronous | Asynchronous |
|---|---|---|
| SOQL queries issued | 100 | 200 |
| Rows retrieved by SOQL | 50,000 | 50,000 |
| DML statements issued | 150 | 150 |
| Rows changed by DML | 10,000 | 10,000 |
| CPU time | 10 seconds | 60 seconds |
| Heap size | 10 MB | 25 MB |
| Callouts | 100 | 100 |
Asynchronous Apex (batch, queueable and future methods) gets the higher figures. Scheduled Apex is an exception: although it runs asynchronously, synchronous limits apply to it. Batch Apex resets the limits for each batch of records it processes.
When code goes over a limit, the platform throws System.LimitException, and that exception can't be caught. The whole transaction rolls back. The only fix is to write code that stays inside the limits in the first place.
Bulkify: one query, not one per record
Scenario: A trigger copies each new contact's account industry into the contact's description. It works when someone creates one contact in the browser, then fails with "Too many SOQL queries: 101" when 200 contacts arrive in a data load.
// Fails on a data load: one query for every contact
for (Contact c : Trigger.new) {
Account a = [SELECT Industry FROM Account WHERE Id = :c.AccountId];
c.Description = a.Industry;
}Triggers receive records in batches of up to 200, so code must work for the whole batch at once. Collect the IDs first, query once, and look records up in a map:
Set<Id> accountIds = new Set<Id>();
for (Contact c : Trigger.new) {
accountIds.add(c.AccountId);
}
Map<Id, Account> accounts = new Map<Id, Account>(
[SELECT Industry FROM Account WHERE Id IN :accountIds]
);
for (Contact c : Trigger.new) {
Account a = accounts.get(c.AccountId);
if (a != null) {
c.Description = a.Industry;
}
}The same rule applies to DML: build a list and insert or update it once, after the loop. The Limits class tells you where you stand while code runs. For example, Limits.getQueries() returns the queries used so far and Limits.getLimitQueries() the ceiling.
Exam tip: "Works for one record but fails on a data load" means a query or DML statement inside a loop. The answer moves it out of the loop and uses a collection, usually a set of IDs and a map. An answer that wraps the code in try/catch never fixes a governor limit.
MVC and the Lightning Component Framework
Salesforce applications follow the model-view-controller (MVC) pattern, which separates data, presentation and logic so that each can change without breaking the others.
| Layer | What it does | On Salesforce |
|---|---|---|
| Model | Holds the data and its rules | Standard and custom objects, fields, relationships, validation rules |
| View | Shows the data and takes input | Lightning web components, Aura components, Visualforce pages, Lightning pages |
| Controller | Connects the two and holds the logic | Apex controllers and extensions, component JavaScript, @AuraEnabled Apex methods |
Lightning components
The Lightning Component Framework builds user interfaces from reusable, self-contained components that run in the browser and fetch data from the server when they need it. It has two programming models:
- Lightning Web Components (LWC) use standard web technologies: modern JavaScript, custom elements and the shadow DOM. Each component is a folder with an HTML template, a JavaScript file and a configuration file, plus optional CSS. LWC is the recommended model for new work because it's lighter and faster.
- Aura components are the original model, with their own markup and JavaScript conventions. Existing Aura code still runs.
The two work together in one direction only: an Aura component can contain a Lightning web component, but a Lightning web component can't contain an Aura component. That matters when you migrate an app gradually, from the inside out.
Components can be placed on Lightning record, app and home pages with Lightning App Builder, in Experience Cloud sites, in the utility bar, in quick actions, in the Salesforce mobile app and inside flow screens.
Visualforce
Visualforce is the older, server-side page framework. A page is tag-based markup rendered on Salesforce's servers, driven by a standard controller (the built-in data and actions for one object), a custom controller written in Apex, or a standard controller with extensions. Visualforce is still supported. It remains the simple choice for a few jobs, such as rendering a page as a PDF.
Scenario: A company wants a new interactive page that updates as the user types, plus a printable quote document. The interactive page is a Lightning web component; the printable document is a Visualforce page rendered as a PDF.
Exam tip: Questions that ask where logic belongs follow MVC: data rules in the model (fields, validation rules), presentation in the view (components, pages) and processing in the controller (Apex). If an answer puts an Aura component inside a Lightning web component, it's wrong.
Declarative or programmatic: choosing the right tool
Salesforce's guiding principle is clicks before code. Declarative features (fields, formulas, validation rules, flows) are faster to build, need no test classes, and can be maintained by administrators. Code is the right answer when the requirement is too complex, too heavy or too specialised for the declarative tools.
Formula fields and roll-up summaries
A formula field is calculated every time the record is read, so it never stores a value of its own and is always current. A formula can reach up to parent records through lookup and master-detail relationships (a cross-object formula, such as Project__r.Project_Code__c), but it can't reach down to child records.
To summarise child records, use a roll-up summary field. It sits on the parent and calculates the COUNT, SUM, MIN or MAX of its child records, optionally filtered (for example, the sum of only the open work items). Roll-up summaries need a master-detail relationship (Account's roll-ups of opportunities are a built-in exception). For a lookup relationship, the summary has to be built with a record-triggered flow or an Apex trigger instead.
Flow or Apex?
| Requirement | Best fit |
|---|---|
| Update fields on the same record when it's saved | Before-save record-triggered flow |
| Create related records, send email, act on a schedule | After-save record-triggered or schedule-triggered flow |
| Complex logic over many related records, or the fastest bulk processing | Apex trigger with a handler class |
| Processing millions of records | Batch Apex |
| A calculation or integration that flows, agents and code all need | An Apex class with an @InvocableMethod, called from each |
| Validation that a formula can express | Validation rule |
| Validation that needs a query or complex logic | addError() in a before trigger |
Flows aren't exempt from governor limits: a flow's queries and DML count against the same transaction limits as Apex. And the two tools combine. A flow can call Apex through an invocable method, so you can keep the process in Flow for administrators and move only the hard part into code.
Scenario: A support manager wants the number of open issues shown on each product record. Issue has a lookup to Product, not a master-detail, so a roll-up summary isn't possible. A record-triggered flow on Issue, or an Apex trigger, recalculates the count when issues are created, closed or deleted.
Exam tip: Read for the relationship type. "Summarise child records over a master-detail relationship" is a roll-up summary; the same requirement over a lookup needs a flow or Apex. A value that must always reflect the parent's current data is a formula field, not a field updated by automation.
Data modelling for developers
Code is only as reliable as the data model underneath it. Developers need to know how each relationship behaves, and how to name it in Apex and SOQL.
| Relationship | Behaviour |
|---|---|
| Lookup | Links to a parent loosely. The parent is optional unless you make it required; child records have their own owner and sharing. |
| Master-detail | The parent (master) is required. Deleting it deletes its details, the details inherit its sharing and owner, and it can hold roll-up summaries. An object can have up to two master-detail relationships. |
| Many-to-many | A junction object with two master-detail relationships, such as an Assignment between Developer and Project. |
| Hierarchical | A special lookup on the User object only, such as a user's manager. |
| External and indirect lookup | Link records to external objects, whose data lives outside Salesforce. |
Naming relationships in code
Custom objects and fields end in __c. The relationship itself ends in __r, and that's the name you use to travel across it:
- Child to parent, with dot notation:
SELECT Name, Project__r.Project_Code__c FROM Work_Item__c. - Parent to children, with a subquery on the child relationship name:
SELECT Name, (SELECT Hours__c FROM Work_Items__r) FROM Project__c.
For standard objects there's no suffix: Contact.Account.Name and (SELECT LastName FROM Contacts).
External IDs and upsert
An External ID is a custom field (text, number, email or auto-number) marked to hold another system's identifier, such as an ERP order number. External ID fields are indexed, and they unlock two things that matter in integrations:
- Upsert inserts or updates in one statement, matching on the external ID:
upsert orders Order_Number__c;. A record whose key isn't found is created, a record found once is updated, and a key found more than once causes an error. - Setting a parent by its external ID, without querying its Salesforce ID first:
new Work_Item__c(Project__r = new Project__c(Project_Code__c = 'P-100')).
Mark the field Unique as well, so that duplicate keys can't creep in.
Scenario: Every night an ERP system sends orders that may be new or may have changed. Loading them with upsert on an External ID field avoids duplicates, needs no query to find existing records, and uses a single DML statement.
Exam tip: "Records from another system, insert or update without creating duplicates" is upsert on an External ID field. "Delete the parent and its children must go too", "the children inherit the parent's sharing" or "roll up the children" all point to master-detail.
Agentforce for Developers, now Agentforce Vibes
The exam outline calls Salesforce's AI coding assistant Agentforce for Developers. Salesforce has since renamed it the Agentforce Vibes extension, and earlier still it was Einstein for Developers. Expect any of these names.
It's a set of AI tools for Salesforce development that runs in Visual Studio Code as part of the Salesforce Extension Pack, and comes preinstalled in the browser-based Agentforce Vibes IDE. It works with Salesforce DX projects, so it isn't available in the Developer Console.
What it's good for
- Generating code from a description: Apex classes and triggers, Lightning web components, and SOQL queries.
- Explaining code you've inherited, and suggesting improvements, including to performance and security.
- Writing unit tests, as a first draft for you to complete.
- Inline autocompletion as you type in Apex and LWC files (JavaScript, HTML and CSS).
- Agentic chat that takes actions in your project, such as deploying, retrieving or running tests. Through the Salesforce DX MCP server it can read your org's metadata, so it generates code that uses your real objects and fields.
- Rules that set lasting standards (naming conventions, error handling) for every session, and Skills that package repeatable tasks.
Its limitations
- Generative AI can produce inaccurate or insecure output, and the same prompt can give different results. Salesforce states that you're responsible for reviewing and testing what it generates before you use it.
- Generated code still has to be bulkified, respect governor limits and sharing, and pass your tests. It's a starting point, not a substitute for code review.
- Generated tests can reach coverage without proving anything. Check that they assert real outcomes.
- The more context you give it (open files, referenced classes, Rules, a connected org), the better its answers. Without that, it doesn't know your org's custom objects.
- Salesforce telemetry must be enabled for it to work.
Scenario: A developer asks the assistant for a trigger that updates related records, and the draft runs a query inside a loop. The developer bulkifies it, writes a test that loads 200 records, and only then deploys.
Exam tip: Answers about using Agentforce for Developers well always include reviewing, testing and checking generated code before deployment. An answer that deploys AI-generated code straight to production, or treats it as proven correct, is wrong.
Hands-on exercise
Model a project tracker and load it by external ID
Create two related objects with a roll-up and a cross-object formula, then load records with Anonymous Apex using an external ID and read the limits your script used.
Use a free Salesforce Developer Edition org — never a production org.
0 of 8 steps done
How to check your work: There are still exactly two projects, P-100 shows the total of its work items' hours, each work item shows P-100 in its formula field, and the debug line reports 1 of 150 DML statements.
Domain quiz: Developer Fundamentals
10 questions from the 62 in this domain, different each time and checked as you go. Anything you miss is saved to Mistakes review.
- Questions
- 10
- Time
- Untimed
- Feedback
- After each answer
New questions each time you start, drawn from the bank, unseen ones first.