Free Salesforce Platform Developer practice questions

10 free Salesforce Platform Developer practice questions with the correct answer and a full explanation for each, taken from the CertStash pack of 439 questions. Work through them, then open each answer to check your reasoning.

Question 1

Which statement results in an Apex compiler error?

  1. Map<Id,Leas> lmap = new Map<Id,Lead>([Select ID from Lead Limit 8]);
  2. Date d1 = Date.Today(), d2 = Date.ValueOf('2018-01-01');
  3. Integer a=5, b=6, c, d = 7;
  4. List<string> s = List<string>{'a','b','c');
Show answer and explanation

Correct answer: D. List<string> s = List<string>{'a','b','c');

A list literal has to be constructed with the new keyword and closed with the same kind of bracket it opened with. Option D writes List<string> s = List<string>{'a','b','c'); which omits new and closes a brace with a parenthesis, so the compiler rejects it before the code ever runs. The other three lines are legal Apex: multiple variables of one type can be declared and initialised in a single statement, and a declared variable may be left unassigned.

Why the other options are wrong

  • A. This compiles. Leas is read as an unresolved type name only if no such type exists, and the exam prints this line as Map<Id, Lead>, so the statement is a valid map construction from a SOQL result.
  • B. Declaring two Date variables in one statement and initialising them with Date.today() and Date.valueOf() is valid Apex.
  • C. Apex allows several variables of the same type in one declaration, and leaving c uninitialised is legal because it simply defaults to null.

Question 2

A method is passed a list of generic sObjects as a parameter.

What should the developer do to determine which object type (Account, Lead, or Contact, for example) to cast each sObject?

  1. Use the first three characters of the sObject ID to determine the sObject type.
  2. Use the getSObjectType method on each generic sObject to retrieve the sObject token.
  3. Use the getSObjectName method on the sObject class to get the sObject name.
  4. Use a try-catch construct to cast the sObject into one of the three sObject types. ✅Correct Answer: B, Use the getSObjectType method on each generic sObject to retrieve the sObject token. Every sObject instance exposes getSObjectType(), which returns the Schema.SObjectType token for that record's object. Calling it on each generic sObject tells the code exactly what it is holding, and the token can then be compared against Account.SObjectType, Lead.SObjectType and so on, so each record can be cast to the right concrete type. It is the supported, describe-driven way to branch on object type.
Show answer and explanation

Answer and explanation for question 2

Question 3

What should a developer use to implement an automatic Approval Process submission for Cases?

  1. An Assignment Rule
  2. Scheduled Apex
  3. Process Builder
  4. A Workflow Rule
Show answer and explanation

Correct answer: C. Process Builder

Process Builder can submit a record for approval as one of its actions, so a Case can be entered into an Approval Process automatically when the process criteria are met. That makes it the declarative tool built for this exact requirement.

Why the other options are wrong

  • A. Assignment Rules route a Case to a user or queue. They have no approval submission action.
  • B. Scheduled Apex is code, and the requirement is served by a declarative feature. It also runs on a schedule rather than on the record event.
  • D. A Workflow Rule cannot submit a record for approval. Its actions are limited to field updates, email alerts, tasks and outbound messages.

Question 4

When viewing a Quote, the sales representative wants to easily see how many discounted items are included in the Quote Line Items.

What should a developer do to meet this requirement?

  1. Create a trigger on the Quote object that queries the Quantity field on discounted Quote Line Items.
  2. Create a Workflow Rule on the Quote Line Item object that updates a field on the parent Quote when the item is discounted.
  3. Create a roll-up summary field on the Quote object that performs a SUM on the quote Line Item Quantity field, filtered for only discounted Quote Line Items.
  4. Create a formula field on the Quote object that performs a SUM on the Quote Line Item Quantity field, filtered for only discounted Quote Line Items.
Show answer and explanation

Correct answer: C. Create a roll-up summary field on the Quote object that performs a SUM on the quote Line Item Quantity field, filtered for only discounted Quote Line Items.

Quote Line Item is the detail side of a master-detail relationship to Quote, which is exactly the condition a roll-up summary field requires. The roll-up can aggregate the Quantity field and apply a filter so only discounted line items are counted, and the total is maintained by the platform on the parent Quote with no code. That gives the sales representative the figure directly on the Quote record.

Why the other options are wrong

  • A. A trigger is code where a declarative roll-up already does the job, and querying the field does not by itself surface the number on the Quote.
  • B. A Workflow Rule field update cannot aggregate values from many child records into a parent total.
  • D. Formula fields evaluate on a single record and cannot sum values across child records. Cross-object formulas only reach upward to a parent.

Question 5

A Developer wants to get access to the standard price book in the org while writing a test class that covers an OpportunityLineItem trigger.

Which method allows access to the price book?

  1. Use Test.getStandardPricebookId() to get the standard price book ID.
  2. Use @IsTest(SeeAllData=true) and delete the existing standard price book.
  3. Use Test.loadData() and a Static Resource to load a standard price book.
  4. Use @TestVisible to allow the test method to see the standard price book.
Show answer and explanation

Correct answer: A. Use Test.getStandardPricebookId() to get the standard price book ID.

Test.getStandardPricebookId() returns the ID of the org's standard price book from inside a test, which is the supported way to get at it when the test cannot see organisation data. A new PricebookEntry can then be created against that ID so an OpportunityLineItem can be inserted and the trigger exercised.

Why the other options are wrong

  • B. SeeAllData=true couples the test to org data, and deleting the standard price book is destructive and not permitted.
  • C. Test.loadData() loads records from a static resource. The standard price book already exists and cannot be created this way.
  • D. @TestVisible exposes private members of Apex classes to tests. It has nothing to do with record visibility.

Question 6

Where can a developer identify the time taken by each process in a transaction using Developer Console log inspector?

  1. Performance Tree tab under Stack Tree panel
  2. Execution Tree tab under Stack Tree panel
  3. Timeline tab under Execution Overview panel
  4. Save Order tab under Execution Overview panel
Show answer and explanation

Correct answer: C. Timeline tab under Execution Overview panel

The Timeline tab in the Execution Overview panel plots the transaction against elapsed time and shows how long each category of work took, so it is where a developer sees the time consumed by each process. The other panels describe what ran and in what order rather than how long it took.

Why the other options are wrong

  • A. There is no Performance Tree tab. The Stack Tree panel holds Execution Tree and Performance Tree views of call nesting, not per-process timing.
  • B. The Execution Tree shows the hierarchy of what executed, not the duration of each step.
  • D. Save Order shows the order of save operations for the transaction, not timing.

Question 7

A developer working on a time management application wants to make total hours for each timecard available to application users. A timecard entry has a Master-

Detail relationship to a timecard.

Which approach should the developer use to accomplish this declaratively?

  1. A Visualforce page that calculates the total number of hours for a timecard and displays it on the page
  2. A Roll-Up Summary field on the Timecard Object that calculates the total hours from timecard entries for that timecard
  3. A Process Builder process that updates a field on the timecard when a timecard entry is created
  4. An Apex trigger that uses an Aggregate Query to calculate the hours for a given timecard and stores it in a custom field
Show answer and explanation

Correct answer: B. A Roll-Up Summary field on the Timecard Object that calculates the total hours from timecard entries for that timecard

Timecard Entry is the detail side of a master-detail relationship to Timecard, so a roll-up summary field on Timecard can SUM the hours from its entries. The platform maintains the total automatically and it is available to users on the Timecard record, which satisfies the requirement declaratively with no code.

Why the other options are wrong

  • A. A Visualforce page is code, so it fails the declarative requirement.
  • C. A Process Builder field update would have to recalculate the running total itself and would miss updates and deletes that a roll-up handles natively.
  • D. An Apex trigger is code, which the question rules out.

Question 8

Which approach should be used to provide test data for a test class?

  1. Query for existing records in the database.
  2. Execute anonymous code blocks that create data.
  3. Use a test data factory class to create test data.
  4. Access data in @TestVisible class variables.
Show answer and explanation

Correct answer: C. Use a test data factory class to create test data.

A test data factory is a dedicated class that builds the records tests need, so setup logic is written once and reused across the whole test suite. Tests stay isolated from org data, remain valid when required fields change because only the factory has to be updated, and each test still runs against data it created itself.

Why the other options are wrong

  • A. Querying existing records makes tests depend on org data, which is unavailable by default and differs between orgs, so tests become fragile.
  • B. Anonymous blocks are run manually and are not part of the test run, so they cannot supply data to a test method.
  • D. @TestVisible only widens access to private members. It does not create records.

Question 9

Which approach should a developer take to automatically add a `Maintenance Plan` to each Opportunity that includes an `Annual Subscription` when an opportunity is closed?

  1. Build a OpportunityLineItem trigger that adds a PriceBookEntry record.
  2. Build an OpportunityLineItem trigger to add an OpportunityLineItem record.
  3. Build an Opportunity trigger that adds a PriceBookEntry record.
  4. Build an Opportunity trigger that adds an OpportunityLineItem record.
Show answer and explanation

Correct answer: D. Build an Opportunity trigger that adds an OpportunityLineItem record.

OpportunityLineItem record. The requirement fires when the Opportunity is closed, so the trigger belongs on Opportunity where that field change is visible. What has to be added is a product line on the Opportunity, and product lines are OpportunityLineItem records. So the answer is an Opportunity trigger that inserts an OpportunityLineItem.

Why the other options are wrong

  • A. The event is the Opportunity closing, which an OpportunityLineItem trigger does not see, and a PricebookEntry is a price list entry rather than a line on the deal.
  • B. The trigger is on the wrong object: closing the Opportunity does not fire an OpportunityLineItem trigger.
  • C. A PricebookEntry adds a product to a price book. It does not add anything to the Opportunity.

Question 10

What is the requirement for a class to be used as a custom Visualforce controller?

  1. Any top-level Apex class that has a constructor that returns a PageReference
  2. Any top-level Apex class that extends a PageReference
  3. Any top-level Apex class that has a default, no-argument constructor
  4. Any top-level Apex class that implements the controller interface
Show answer and explanation

Correct answer: C. Any top-level Apex class that has a default, no-argument constructor

When a page names a custom controller, the platform has to instantiate that class with no arguments, so the class must be a top-level Apex class with a default no-argument constructor. Nothing else is required: no interface, no particular return type.

Why the other options are wrong

  • A. A constructor cannot return a PageReference. Constructors return nothing, and action methods are what return PageReference.
  • B. PageReference is not extendable, and a controller does not derive from it.
  • D. There is no controller interface to implement. Standard controller extensions take a StandardController argument, but that is a different scenario.

That was 10 of 439.

The full Salesforce Platform Developer pack has all 439 questions, each with the answer, the explanation and why the other options are wrong, plus a questions-only copy for timed runs. US$39, paid once, with free monthly updates and a pass-or-your-money-back guarantee.

Get the full pack