All Salesforce exams

Free Salesforce Certified Platform Developer practice test: 30 questions with answers

30 original questions for Salesforce Certified Platform Developer, drawn from every topic area. Answer each one to see whether you got it right and why. No sign-up.

Free questions
30
Full bank
112 questions
Real exam
60 questions, 105 min
Passing score
68%

Salesforce Certified Platform Developer exam guide: topics, cost and format

All 30 Salesforce Certified Platform Developer questions with answers

The same questions as the test above, grouped by exam topic. Open any question to see the answer and explanation.

Process Automation and Logic (8 questions)

  1. Question 1

    A developer needs a class-level value that is set once and cannot be reassigned anywhere in the code. Which declaration meets this need?

    1. Astatic final Integer MAX_ROWS = 100;
    2. Bpublic Integer MAX_ROWS = 100;
    3. Cstatic Integer MAX_ROWS = 100;
    4. Dprivate const Integer MAX_ROWS = 100;
    Show answer and explanation
    Correct answer: A

    The static modifier ties the value to the class, and final stops it from being reassigned after it is set. The instance field and the plain static field can both be changed, and const is not an Apex keyword.

  2. Question 2

    A developer defines a global interface named Notifier with one method, send(). Which statement describes how a class must use this interface?

    1. AThe class uses extends and inherits the send() body from the interface
    2. BThe interface is instantiated with new, and the class calls send() on that instance
    3. CThe class uses implements and must provide its own body for send()
    4. DThe class receives send() automatically without code if it sits in the same namespace
    Show answer and explanation
    Correct answer: C

    A class uses implements and must write a body for every method the interface declares, because Apex interfaces contain only method signatures. extends is for classes, interfaces cannot be instantiated, and no implementation is supplied automatically.

  3. Question 3

    Inside a for loop over a List, a developer executes a break statement under a certain condition. What happens next?

    1. AIt exits the loop immediately and runs the first statement after the loop
    2. BIt ends the entire method and returns null to the code that called the method
    3. CIt skips the rest of the current iteration and moves on to the next element in the list
    4. DIt restarts the loop from the first element of the collection and counts the iterations again
    Show answer and explanation
    Correct answer: A

    break leaves the innermost loop at once, and execution continues with the statement after the loop. The skip-to-next-iteration behaviour belongs to continue, and break neither returns from the method nor restarts the loop.

  4. Question 4

    Which two practices make a trigger safe when a data load inserts many records at once? (Choose two.)

    1. ACollect the related Ids into a Set and query the related records once for the whole batch
    2. BPlace an update DML statement inside the for loop so each record is saved as it is processed
    3. CStore the related records in a Map keyed by Id so each record can be matched without another query
    4. DRun a SOQL query for each record in Trigger.new to fetch its parent record
    5. EProcess only the first record in Trigger.new and leave the rest of the batch unhandled
    Show answer and explanation
    Correct answer: A, C

    Querying once for the whole batch and matching results through a Map keeps SOQL and DML counts flat no matter how many records arrive. DML or SOQL inside the loop repeats the cost for every record, and processing only the first record leaves the rest of the batch unhandled.

  5. Question 5

    An app needs one search box that looks for a text term across Account, Contact and Lead records, matching any of several text fields at once. Which query language fits?

    1. ASOQL, using a single query that joins Account, Contact and Lead together
    2. BA DML upsert with an external ID field matched against the search term
    3. CSOQL with a LIKE filter on every field of each object in one statement
    4. DSOSL, using FIND with a RETURNING clause that lists the objects to search
    Show answer and explanation
    Correct answer: D

    SOSL searches text fields across several objects in one call with FIND and RETURNING, which matches this pattern. SOQL reads one object and its related records, so it cannot join unrelated objects or search every field, and upsert writes records rather than searching them.

  6. Question 6

    A team has three separate triggers on the Opportunity object, each with its own logic for the same events. Which structure follows Salesforce trigger best practice?

    1. AA separate trigger for every field that changes, each with its own copy of the logic
    2. BSeparate triggers per user profile so that each team runs its own version of the logic
    3. COne trigger per object that runs all of its logic inline in the trigger body
    4. DOne trigger per object that hands the work to a handler class
    Show answer and explanation
    Correct answer: D

    The recommended pattern is one trigger per object that delegates to handler classes, which keeps logic in one organized and testable place. Per-field and per-profile triggers cause duplicated or unpredictable behaviour, and inline logic is hard to test and reuse.

  7. Question 7

    A workflow field update changes a field on an Account, and a before update trigger on Account changes the same record. The trigger logic runs a second time within one save. What is the most appropriate fix?

    1. ADisable the Account trigger in Setup while the workflow rule is active
    2. BMove the trigger logic into a Visualforce page so that it runs only once per save
    3. CRename the trigger so that Salesforce skips it on the second pass through the record
    4. DAdd a static Boolean flag in an Apex class and skip logic that has already run
    Show answer and explanation
    Correct answer: D

    A static variable lasts for the whole transaction, so a flag set on the first pass lets the trigger skip work on the re-run that the workflow causes. Disabling the trigger, moving logic to a page, or renaming the trigger does not guard against the repeat run.

  8. Question 8

    In a before insert trigger, a developer must stop a bad Opportunity from being saved and show the user an error message on the record. Which approach does that?

    1. ASet the Name field to the error text so that the user notices it the next time they open the list view
    2. BCall System.debug with the error text so that it appears in the debug log for later review by an admin
    3. CCall addError on the record with the message so that the save is blocked and the user sees it
    4. DCreate a Task on the record with the error text so that the owner is reminded to fix it
    Show answer and explanation
    Correct answer: C

    addError on a record in Trigger.new blocks that record's save and displays the message to the user. Changing the Name field does not stop the save, System.debug only writes to the log, and a Task is created without preventing the save.

Developer Fundamentals (8 questions)

  1. Question 9

    A developer is modeling Project__c records that must always belong to an Account, must be deleted automatically when that Account is deleted, and should take their sharing access from the Account. Which relationship type should be created on Project__c?

    1. AA master-detail relationship to Account
    2. BA lookup relationship to Account that is optional
    3. CA hierarchical relationship to Account
    4. DAn external lookup relationship to Account
    Show answer and explanation
    Correct answer: A

    A master-detail relationship makes the child required, cascades deletes from the parent, and inherits sharing from it. A lookup is optional with no cascade delete, hierarchical relationships exist only on the User object, and external lookups point to external data rather than Account records.

  2. Question 10

    Which statement about an External ID field on a custom object is correct?

    1. AIt is a formula field whose value is calculated from a parent record's Id
    2. BIt is automatically populated with the 18-character Salesforce record Id
    3. CIt stores a value from an outside system and can be used to match records during an upsert
    4. DIt can only be applied to standard objects such as Account and Contact, not to custom objects
    Show answer and explanation
    Correct answer: C

    An External ID field stores an identifier from another system so that upsert can match an incoming record to an existing one without knowing its Salesforce Id. It is not a formula, it is not filled in automatically with the record Id, and it is not limited to standard objects.

  3. Question 11

    A trigger on Contact receives a batch of 200 records. Inside the loop, the developer runs a SOQL query on Account for each Contact to read the Account industry. What is the best fix?

    1. AKeep the query inside the loop but add a LIMIT 1 clause so that each Contact retrieves only one Account row
    2. BSplit the trigger into two separate triggers so that each trigger handles only half of the incoming Contact records
    3. CMove the query into a Visualforce controller method that the page calls once for each Contact row displayed
    4. DCollect the AccountIds first, run one query before the loop, and store the results in a Map for lookups
    Show answer and explanation
    Correct answer: D

    Running one SOQL query per record can exceed the per-transaction SOQL governor limit, so the query should run once with a set of Ids and the results should be kept in a Map. The other options still query per record or only move or split the same work without reducing the number of queries.

  4. Question 12

    Which two statements about Salesforce's multi-tenant architecture are correct? (Choose two.)

    1. AEach customer org runs on its own dedicated physical database server
    2. BMany customer orgs share the same underlying infrastructure while their data stays logically separated
    3. CApex code in one org can query records stored in another customer's org by default
    4. DGovernor limits exist so that one tenant's code cannot monopolize shared resources
    5. EEach developer must install and maintain the database engine for their own org
    Show answer and explanation
    Correct answer: B, D

    Multi-tenancy means many customers share the same infrastructure with logically separated data, and governor limits keep one tenant from monopolizing shared resources. Dedicated servers per org, default cross-org queries, and self-maintained database engines do not describe how the platform works.

  5. Question 13

    A team is building a new reusable component for Lightning Experience and wants it to follow current web standards such as custom elements and the shadow DOM. Which framework should they choose?

    1. AVisualforce pages with custom JavaScript libraries loaded through static resources
    2. BThe Lightning Component Framework using Aura markup and controllers
    3. CLightning Web Components
    4. DDeclarative flow screens built only from standard screen components
    Show answer and explanation
    Correct answer: C

    Lightning Web Components are built on standard web component APIs, including custom elements and the shadow DOM. Aura is Salesforce's older proprietary component model, Visualforce is a page framework, and declarative flow screens do not expose web component code.

  6. Question 14

    A business wants to stop users from saving an Opportunity as Closed Won when the Amount field is blank, and the rule must be built without writing any code. Which tool fits best?

    1. AA Visualforce page with a custom save controller
    2. BA validation rule on the Opportunity object
    3. CA static resource containing a JavaScript validator
    4. DA before insert Apex trigger that checks the Amount field
    Show answer and explanation
    Correct answer: B

    A validation rule is a declarative formula that blocks a save and shows an error when its condition is true, so it needs no code. Triggers, Visualforce controllers and JavaScript validators all require code and do not meet the no-code requirement.

  7. Question 15

    A recruiting company needs each Candidate to apply to many Job Postings and each Job Posting to receive applications from many Candidates. Which data model is the standard choice?

    1. AA junction object with two master-detail relationships, one to each parent object
    2. BA lookup field on Job Posting that points to a single Candidate record
    3. CA self-lookup on the Candidate object that points back to other Candidate records
    4. DA text field on each Candidate that stores a comma-separated list of Job Posting Ids
    Show answer and explanation
    Correct answer: A

    A many-to-many relationship is modeled with a junction object that has a master-detail relationship to each parent. A single lookup allows only one parent per record, a self-lookup relates Candidates only to Candidates, and a comma-separated text field cannot be queried or reported relationally.

  8. Question 16

    A developer uses an AI coding assistant to draft an Apex class for a production feature. What should happen before the code is deployed?

    1. AThe code is deployed directly because AI-generated Apex is pre-approved by Salesforce
    2. BTest classes are skipped because the assistant has already verified the logic for the feature
    3. CThe developer reviews the generated code, writes tests, and checks limits and sharing rules
    4. DSharing is turned off for the class so that every query the assistant wrote will succeed
    Show answer and explanation
    Correct answer: C

    AI-generated code is a draft that still needs human review, test coverage, and checks against governor limits and sharing rules before production. The other options skip verification or weaken security, which is unsafe.

User Interface (7 questions)

  1. Question 17

    A Visualforce page displays a comment that a user typed into an apex:outputText component. A tester enters a script tag, and the script must not run in the browser. What default behaviour protects the page?

    1. AVisualforce strips every character that is not a letter or number from the value before display
    2. BVisualforce escapes the output by default, so the characters display as text rather than running
    3. CVisualforce disables all JavaScript on any page that shows data entered by an end user
    4. DVisualforce stores user input in an encrypted form so that the browser cannot decode the script text
    Show answer and explanation
    Correct answer: B

    Visualforce output components escape special characters by default because the escape attribute is true, so the browser renders the script as plain text. Stripping characters, disabling all JavaScript, or encrypting the input are not how this default protection works.

  2. Question 18

    Which statement about the with sharing keyword on an Apex class is correct?

    1. AIt skips field-level security checks for every field that the class queries
    2. BIt makes the class enforce the running user's record-level sharing rules
    3. CIt runs the class in system mode, so record-level access rules are ignored
    4. DIt hides any field from users whose profile lacks read access to that field
    Show answer and explanation
    Correct answer: B

    with sharing applies the running user's record-level sharing rules to queries and DML in the class. Field-level security is a separate check, and running in system mode ignores record-level sharing, which is the opposite of with sharing.

  3. Question 19

    A developer wants a SOQL query to throw an exception when the running user lacks read access to any field the query selects, instead of silently returning those fields. Which addition meets this need?

    1. AA LIMIT 1 clause that caps the number of rows the query can return to one
    2. BA FOR UPDATE clause that locks the returned records until the transaction ends
    3. CA WITH SYSTEM_MODE clause that runs the query without enforcing field-level access
    4. DA WITH SECURITY_ENFORCED clause that checks the user's field and object access
    Show answer and explanation
    Correct answer: D

    WITH SECURITY_ENFORCED makes the query check field and object read access for the running user and throw an exception when access is missing. LIMIT caps rows, FOR UPDATE locks records, and WITH SYSTEM_MODE skips field-level checks, so none of those meets the requirement.

  4. Question 20

    A developer builds a Lightning Web Component that must run an existing screen flow inside the component. Which base component should the template use?

    1. Alightning-record-form, which displays the fields of a single record for viewing and editing
    2. Blightning-flow, which runs a flow and displays its screens in the component
    3. Clightning-datatable, which shows a set of records in rows and columns
    4. Dlightning-input-field, which edits the value of one field on a record
    Show answer and explanation
    Correct answer: B

    lightning-flow embeds and runs a flow, with its screens displayed in the component. The other base components show a record's fields, show a grid of rows, or edit one field, and none of them runs a flow.

  5. Question 21

    A Visualforce page must show the Account whose Id is passed in the URL, using built-in Account behaviour rather than a custom Apex class. Which apex:page attribute should be set?

    1. Acontroller attribute set to the name of a custom Apex class
    2. BsObjectType attribute set to the name of the Account object
    3. Cextensions attribute set to the name of the Account object
    4. DstandardController attribute set to the Account object
    Show answer and explanation
    Correct answer: D

    standardController takes the object name, here Account, and gives the page built-in record behaviour. controller names a custom Apex class, extensions names Apex classes that add logic on top of a standard controller, and sObjectType is not an apex:page attribute.

  6. Question 22

    A child Lightning Web Component needs to tell its parent that the user picked a row. Which approach follows the recommended communication pattern?

    1. AThe child dispatches a custom event that the parent template handles with an event handler
    2. BThe parent edits the child's private properties directly from its own JavaScript code
    3. CThe child calls a method on a sibling component that is stored in a global variable
    4. DThe child writes the selected row to the window object so that the parent can read it later
    Show answer and explanation
    Correct answer: A

    Events travel up the component tree: the child dispatches a CustomEvent and the parent listens with an event handler in its template. Parents should not reach into a child's private state, and global or window storage bypasses the component model.

  7. Question 23

    A Visualforce page needs JavaScript to call a controller method and refresh one section of the page without a full page reload. Which component should the developer use?

    1. Aapex:outputLink, which navigates to a URL when the user clicks it
    2. Bapex:actionFunction, which creates a JavaScript function that calls a controller action
    3. Capex:repeat, which loops over a list and renders the markup for each item
    4. Dapex:includeScript, which loads an external JavaScript file into the page
    Show answer and explanation
    Correct answer: B

    apex:actionFunction generates a JavaScript function that invokes a controller action and can re-render part of the page. outputLink navigates to another URL, repeat only iterates over a collection, and includeScript only loads a script file.

Testing, Debugging, and Deployment (7 questions)

  1. Question 24

    Before a team deploys Apex to a production org, it asks what minimum share of Apex code must be covered by tests. Which answer is correct?

    1. ASeventy-five percent overall coverage of the lines in the org's Apex classes and triggers
    2. BFifty percent overall coverage of the lines in the org's Apex classes and triggers
    3. CNinety percent coverage of the lines in each individual Apex class and trigger in the org
    4. DOne hundred percent coverage of the lines in each individual Apex class and trigger in the org
    Show answer and explanation
    Correct answer: A

    Production deployments require at least 75 percent overall Apex code coverage across the org. Fifty percent falls below the required threshold, while the 90 and 100 percent options describe targets that are not the minimum requirement.

  2. Question 25

    A test method must check the outcome of a Queueable job that the code under test enqueues. Which pair of calls should wrap the code under test so that the job runs before the assertions and governor limits are reset?

    1. ASystem.runAs() and System.assert()
    2. BDatabase.setSavepoint() and Database.rollback()
    3. CTest.startTest() and Test.stopTest()
    4. D@TestSetup and @IsTest annotations on the test class
    Show answer and explanation
    Correct answer: C

    Test.startTest() gives the code under test a fresh set of governor limits, and Test.stopTest() makes queued asynchronous work run before the test continues. runAs changes the user context, savepoint and rollback manage transactions, and TestSetup creates shared test data.

  3. Question 26

    Which two statements about scratch orgs are correct? (Choose two.)

    1. AThey are created from a scratch org definition file
    2. BThey are designed to be temporary and expire after a set period
    3. CThey always contain a full copy of the production data
    4. DThey are permanent orgs that cannot be deleted once they are created
    5. EThey are intended to hold live customer records for daily business use
    Show answer and explanation
    Correct answer: A, B

    Scratch orgs are built from a definition file and are meant to be temporary, expiring after a set period. They do not copy production data and are not designed for live business records, and permanent orgs are a different kind of org.

  4. Question 27

    A developer wants to run a few lines of Apex that create test records and print the output, without saving a class first. Which Developer Console feature is designed for this?

    1. AQuery Editor, which runs SOQL statements against the org's data
    2. BExecute Anonymous window, which runs Apex code snippets directly from the console
    3. CLog Inspector, which filters and analyses existing debug logs
    4. DCheckpoints feature, which captures variable state at chosen lines of code
    Show answer and explanation
    Correct answer: B

    The Execute Anonymous window runs Apex typed straight into the console without creating a class, and it shows the debug output. The Query Editor runs SOQL, the Log Inspector reviews existing logs, and Checkpoints record variable state at chosen lines in a log rather than running new code.

  5. Question 28

    An administrator needs to check the status, items processed and error count for a batch Apex job that ran overnight. Where should the admin look in Setup?

    1. AApex Jobs page, which lists asynchronous jobs and their status
    2. BCompany Information page, which holds the org's address and time zone
    3. CInstalled Packages page, which lists the managed packages in the org
    4. DEmail Deliverability page, which controls outbound email settings
    Show answer and explanation
    Correct answer: A

    The Apex Jobs page in Setup lists asynchronous work such as batch jobs with their status and error counts, which fits an overnight batch. The other pages show installed packages, company profile details, and email settings, none of which track batch progress.

  6. Question 29

    A test class must cover code that makes an HTTP callout to an external service, and the test must not call the real service. Which approach does that?

    1. ACall the external service from the test and assert on the live response
    2. BRegister an HttpCalloutMock class with Test.setMock before the code under test runs
    3. CSkip the callout by catching the exception in the test method without any mock
    4. DAdd SeeAllData=true to the test class so that existing callout records in the org are reused
    Show answer and explanation
    Correct answer: B

    Test.setMock registers a class that implements HttpCalloutMock, so the code under test receives a canned response instead of calling the real service. Calling the live service makes tests unreliable, SeeAllData exposes org data rather than mocking the callout, and swallowing the exception hides the behaviour under test.

  7. Question 30

    A developer wants to push the source in a local Salesforce DX project to a target org from the command line. Which command does that?

    1. Asf project deploy start, which deploys local source to the target org
    2. Bsf org create scratch, which creates a new temporary scratch org
    3. Csf project retrieve start, which copies metadata from the org into the project
    4. Dsf apex run test, which runs the Apex tests already in the org
    Show answer and explanation
    Correct answer: A

    sf project deploy start pushes source from the local project to the target org. The retrieve command goes the other way, org create scratch makes a new org, and apex run test runs existing tests without deploying anything.