Salesforce Certified Platform Developer I Practice Questions with Explanations
Free Salesforce Certified Platform Developer I practice questions. 50 of them, each with the correct answer, a full explanation, and the reason every other option is wrong. These are real questions from the Salesforce Certified Platform Developer I exam, not paraphrases, and every explanation is written out rather than just marking the right letter.
They are drawn from the same bank as the full Salesforce Certified Platform Developer I pack, which has 439 questions in total.
Get the full Salesforce Certified Platform Developer I question bank (439 questions) →
Salesforce Certified Platform Developer I practice questions
Question 1
Which statement results in an Apex compiler error?
- A. Map<Id,Leas> lmap = new Map<Id,Lead>([Select ID from Lead Limit 8]);
- B. Date d1 = Date.Today(), d2 = Date.ValueOf('2018-01-01');
- C. Integer a=5, b=6, c, d = 7;
- D. List<string> s = List<string>{'a','b','c');
Show answer and explanation ▾
Correct answer: D
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?
- A. Use the first three characters of the sObject ID to determine the sObject type.
- B. Use the getSObjectType method on each generic sObject to retrieve the sObject token.
- C. Use the getSObjectName method on the sObject class to get the sObject name.
- D. Use a try-catch construct to cast the sObject into one of the three sObject types.
Show answer and explanation ▾
Correct answer: B
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, or fed to newSObject() to cast. It is the supported, describe-driven way to branch on object type.
Why the other options are wrong:
- A. Key prefixes do identify an object, but reading the first three characters of an ID means hardcoding prefixes or querying EntityDefinition to map them. It is indirect and brittle next to a single method call.
- C. There is no getSObjectName method on the sObject class. The describe result exposes getName(), reached through getSObjectType().getDescribe().
- D. Casting inside a try-catch treats a type check as an exception handler. It works only by failing repeatedly and is not how type is determined.
Question 3
What should a developer use to implement an automatic Approval Process submission for Cases?
- A. An Assignment Rule
- B. Scheduled Apex
- C. Process Builder
- D. A Workflow Rule
Show answer and explanation ▾
Correct answer: C
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?
- A. Create a trigger on the Quote object that queries the Quantity field on discounted Quote Line Items.
- B. Create a Workflow Rule on the Quote Line Item object that updates a field on the parent Quote when the item is discounted.
- 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.
- D. 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
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?
- A. Use Test.getStandardPricebookId() to get the standard price book ID.
- B. Use @IsTest(SeeAllData=true) and delete the existing standard price book.
- C. Use Test.loadData() and a Static Resource to load a standard price book.
- D. Use @TestVisible to allow the test method to see the standard price book.
Show answer and explanation ▾
Correct answer: A
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?
- A. Performance Tree tab under Stack Tree panel
- B. Execution Tree tab under Stack Tree panel
- C. Timeline tab under Execution Overview panel
- D. Save Order tab under Execution Overview panel
Show answer and explanation ▾
Correct answer: C
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?
- A. A Visualforce page that calculates the total number of hours for a timecard and displays it on the page
- B. A Roll-Up Summary field on the Timecard Object that calculates the total hours from timecard entries for that timecard
- C. A Process Builder process that updates a field on the timecard when a timecard entry is created
- D. 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
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?
- A. Query for existing records in the database.
- B. Execute anonymous code blocks that create data.
- C. Use a test data factory class to create test data.
- D. Access data in @TestVisible class variables.
Show answer and explanation ▾
Correct answer: C
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?
- A. Build a OpportunityLineItem trigger that adds a PriceBookEntry record.
- B. Build an OpportunityLineItem trigger to add an OpportunityLineItem record.
- C. Build an Opportunity trigger that adds a PriceBookEntry record.
- D. Build an Opportunity trigger that adds an OpportunityLineItem record.
Show answer and explanation ▾
Correct answer: D
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?
- A. Any top-level Apex class that has a constructor that returns a PageReference
- B. Any top-level Apex class that extends a PageReference
- C. Any top-level Apex class that has a default, no-argument constructor
- D. 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.
Question 11
A Visualforce page is required for displaying and editing Case records that includes both standard and custom functionality defined in an Apex class called myControllerExtension. The Visualforce page should include which <apex:page> attribute(s) to correctly implement controller functionality?
- A. controller="Case" and extensions="myControllerExtension"
- B. extensions="myControllerExtension"
- C. controller="myControllerExtension"
- D. standardController="Case" and extensions="myControllerExtension"
Show answer and explanation ▾
Correct answer: D
The page needs the standard Case behaviour for displaying and editing the record plus the custom logic in the Apex class, so it uses standardController="Case" to get the built-in functionality and extensions="myControllerExtension" to layer the custom methods on top. Both attributes are required together.
Why the other options are wrong:
- A. controller specifies a custom controller. Case is a standard object, so it belongs in standardController, and naming it in controller would not resolve to a class.
- B. extensions cannot be used on its own. It always extends a standard or custom controller that must also be declared.
- C. Naming the extension class as the controller loses all the standard Case display and edit behaviour the page requires.
Question 12
A newly hired developer discovers that there are multiple triggers on the case object. What should the developer consider when working with triggers?
- A. Developers must dictate the order of trigger execution.
- B. Trigger execution order is based on creation date and time.
- C. Unit tests must specify the trigger being tested.
- D. Trigger execution order is not guaranteed for the same sObject.
Show answer and explanation ▾
Correct answer: D
If more than one trigger is defined on an object for the same event, Salesforce does not guarantee the order in which they execute. That is the key consideration when inheriting an object that already carries several triggers, and it is the reason the one-trigger-per- object pattern exists.
Why the other options are wrong:
- A. Developers cannot dictate execution order across separate triggers. They can only control ordering by consolidating the logic into a single trigger.
- B. Order is not determined by creation date and time, and relying on it would be unsafe even if it happened to correlate.
- C. Unit tests exercise triggers by performing DML. There is no way, and no need, to name the trigger under test.
Question 13
How should a developer prevent a recursive trigger?
- A. Use a "one trigger per object" pattern.
- B. Use a static Boolean variable.
- C. Use a trigger handler.
- D. Use a private Boolean variable.
Show answer and explanation ▾
Correct answer: B
A static Boolean variable holds its value for the life of the transaction, so the trigger can set it the first time it runs and check it on re-entry to skip the logic. That transaction-scoped flag is the standard guard against recursion caused by a trigger's own DML firing the trigger again.
Why the other options are wrong:
- A. One trigger per object controls ordering and keeps logic in one place. It does not stop that single trigger from firing itself again.
- C. A trigger handler organises code. Recursion still has to be prevented by a flag inside it.
- D. A private instance variable is recreated on each trigger invocation, so its value does not survive to the next run and it cannot detect re-entry.
Question 14
A developer has the controller class below. Which code block will run successfully in an execute anonymous window?
- A. myFooController m = new myFooController(); System.assert(m.prop !=null);
- B. myFooController m = new myFooController(); System.assert(m.prop ==0);
- C. myFooController m = new myFooController(); System.assert(m.prop ==null);
- D. myFooController m = new myFooController(); System.assert(m.prop ==1);
Show answer and explanation ▾
Correct answer: C
An Apex variable that is declared but never assigned holds null, and the controller's constructor does not initialise prop. So after constructing the controller, prop is null and only the assertion that compares it to null passes. Every option compiles and runs, but this is the one whose assertion evaluates to true.
Why the other options are wrong:
- A. prop is null, so asserting that it is not null fails.
- B. An uninitialised variable does not default to zero in Apex. Numeric types default to null like everything else.
- D. Nothing in the constructor sets prop to 1, so this assertion fails.
Question 15
In a single record, a user selects multiple values from a multi-select picklist. How are the selected values represented in Apex?
- A. As a List<String> with each value as an element in the list
- B. As a String with each value separated by a comma
- C. As a String with each value separated by a semicolon
- D. As a Set<String> with each value as an element in the set
Show answer and explanation ▾
Correct answer: C
A multi-select picklist stores its selected values in a single text field, with the individual values separated by semicolons. In Apex the field therefore reads as one String, and code that needs the values as a collection splits it on the semicolon.
Why the other options are wrong:
- A. Apex does not hand back a List<String>. The developer has to produce one by splitting the stored string.
- B. The separator is a semicolon, not a comma. A comma would be ambiguous because values may contain commas.
- D. There is no automatic Set<String> representation, and a set would also discard the stored order.
Question 16
A developer writes the following code: What is the result of the debug statement?
- A. 1, 100
- B. 1, 150
- C. 2, 150
- D. 2, 200
Show answer and explanation ▾
Correct answer: C
The debug prints the number of DML statements used and the DML limit for the transaction. The code performs two DML operations, because Database.emptyRecycleBin() counts against the DML statement limit just as insert, update and delete do. The synchronous limit on DML statements per transaction is 150, so the result is 2 and 150.
Why the other options are wrong:
- A. This undercounts the DML statements and uses the wrong limit value.
- B. The limit of 150 is right but only one DML statement is counted, which misses emptyRecycleBin.
- D. The count of 2 is right, but 200 is not the DML statement limit. 200 is the trigger batch size.
Question 17
How should a developer make sure that a child record on a custom object, with a lookup to the Account object, has the same sharing access as its associated account?
- A. Create a Sharing Rule comparing the custom object owner to the account owner.
- B. Create a validation rule on the custom object comparing the record owners on both records.
- C. Include the sharing related list on the custom object page layout.
- D. Ensure that the relationship between the objects is Master-Detail.
Show answer and explanation ▾
Correct answer: D
In a master-detail relationship the detail record has no owner of its own and inherits sharing and access directly from its master. Changing the lookup to a master-detail therefore guarantees that the child record has exactly the same sharing access as its Account, with nothing to keep in step.
Why the other options are wrong:
- A. Owner-based sharing rules grant extra access but do not make the child's access mirror the parent's, and they cannot express "whatever the account has".
- B. A validation rule enforces data entry conditions. It has no effect on record access.
- C. The sharing related list only shows who has access. It does not confer any.
Question 18
An org has a single account named `˜NoContacts' that has no related contacts. Given the query: List<Account> accounts = [Select ID, (Select ID, Name from Contacts) from Account where Name=`˜NoContacts']; What is the result of running this Apex?
- A. accounts[0].contacts is invalid Apex.
- B. accounts[0].contacts is an empty Apex.
- C. accounts[0].contacts is Null.
- D. A QueryException is thrown.
Show answer and explanation ▾
Correct answer: B
A relationship subquery always returns a list. When the parent has no related children the list is present but contains no elements, so accounts[0].contacts is an empty list rather than null. Code can safely call size() or isEmpty() on it and iterating simply does nothing.
Why the other options are wrong:
- A. The syntax is a standard parent-child subquery and is perfectly valid Apex.
- C. The child relationship is populated with an empty list, not left null, because the subquery was part of the query.
- D. No exception is thrown. A parent with no children is an ordinary result.
Question 19
Using the Schema Builder, a developer tries to change the API name of a field that is referenced in an Apex test class. What is the end result?
- A. The API name is not changed and there are no other impacts.
- B. The API name of the field and the reference in the test class is changed.
- C. The API name of the field is changed, and a warning is issued to update the class.
- D. The API name of the field and the reference in the test class is updated.
Show answer and explanation ▾
Correct answer: A
Salesforce refuses to rename a field whose API name is referenced in Apex. The save is rejected, so the field keeps its original API name and nothing else in the org changes. Apex references are hard dependencies and the platform protects them rather than letting code break.
Why the other options are wrong:
- B. The platform does not rewrite Apex source when metadata changes, and in this case the rename does not happen at all.
- C. There is no warn-and-proceed behaviour. The change is blocked outright.
- D. Neither the field nor the class is updated, because the rename fails.
Question 20
When is an Apex Trigger required instead of a Process Builder Process?
- A. When a record needs to be created
- B. When multiple records related to the triggering record need to be updated
- C. When a post to Chatter needs to be created
- D. When an action needs to be taken on a delete or undelete, or before a DML operation is executed.
Show answer and explanation ▾
Correct answer: D
Process Builder runs after the record is saved and only on create and update. A trigger is required when the logic must respond to a delete or an undelete, or must run before the DML operation completes so it can change field values in place or block the save. Those events are outside what the declarative tool can reach.
Why the other options are wrong:
- A. Process Builder can create records, so a trigger is not required.
- B. Process Builder can update related records, so this does not force code either.
- C. Posting to Chatter is an available Process Builder action.
Question 21
A developer needs to join data received from an integration with an external system with parent records in Salesforce. The data set does not contain the Salesforce IDs of the parent records, but it does have a foreign key attribute that can be used to identify the parent. Which action will allow the developer to relate records in the data model without knowing the Salesforce ID?
- A. Create and populate a custom field on the parent object marked as Unique.
- B. Create a custom field on the child object of type External Relationship.
- C. Create and populate a custom field on the parent object marked as an External ID.
- D. Create a custom field on the child object of type Foreign Key.
Show answer and explanation ▾
Correct answer: C
Marking a custom field on the parent as an External ID lets the platform match on that value instead of a Salesforce ID. The integration's foreign key is stored there, and child records can then be related, or upserted, by referencing the parent through the external ID field, so no Salesforce IDs need to be known in advance.
Why the other options are wrong:
- A. Unique enforces that no two records share a value but does not make the field usable as a matching key for relating or upserting records.
- B. There is no External Relationship field type on standard or custom objects.
- D. There is no Foreign Key field type in Salesforce. Relationships are Lookup or Master- Detail.
Question 22
A developer created a Lightning component to display a short text summary for an object and wants to use it with multiple Apex classes. How should the developer design the Apex classes?
- A. Have each class define method getObject() that returns the sObject that is controlled by the Apex class.
- B. Extend each class from the same base class that has a method getTextSummary() that returns the summary.
- C. Have each class implement an interface that defines method getTextSummary() that returns the summary.
- D. Have each class define method getTextSummary() that returns the summary.
Show answer and explanation ▾
Correct answer: C
The component needs one guaranteed method, getTextSummary(), across classes that are otherwise unrelated and may already sit in their own hierarchies. An interface states that contract without dictating a parent class, lets each class supply its own implementation, and allows the component to hold any of them in a variable of the interface type and call the method polymorphically. That is the standard use for an interface.
Why the other options are wrong:
- A. Returning the sObject pushes the summary logic back into the component and does not give it a summary method to call.
- B. A base class forces every class into one inheritance chain, which Apex allows only once per class, and these classes are unrelated.
- D. Defining the same method on each class independently gives no common type, so the component cannot call it without knowing each concrete class.
Question 23
Which approach should a developer use to add pagination to a Visualforce page?
- A. A StandardController
- B. The Action attribute for a page
- C. The extensions attribute for a page
- D. A StandardSetController
Show answer and explanation ▾
Correct answer: D
StandardSetController is built for working with a set of records and exposes the pagination members directly: setPageSize, next, previous, hasNext, hasPrevious and getRecords. Binding a page to it gives paging with almost no custom code.
Why the other options are wrong:
- A. A StandardController handles a single record and has no notion of pages.
- B. The action attribute runs a method on page load. It is not a paging mechanism.
- C. extensions attaches Apex to a controller. It is where paging code could live, but the controller that actually provides pagination is the StandardSetController.
Question 24
Which tool allows a developer to send requests to the Salesforce REST APIs and view the responses?
- A. REST resource path URL
- B. Workbench REST Explorer
- C. Developer Console REST tab
- D. Force.com IDE REST Explorer tab
Show answer and explanation ▾
Correct answer: B
Workbench includes a REST Explorer under its Utilities menu that lets a developer choose an HTTP method, enter a resource path, send the request against the authenticated org and read the raw response. It is the tool built for exactly this.
Why the other options are wrong:
- A. A resource path URL is the address of an endpoint, not a tool for issuing requests and inspecting responses.
- C. The Developer Console has no REST tab. It offers the Query Editor and anonymous Apex execution.
- D. The Force.com IDE has no REST Explorer tab.
Question 25
A developer created a Visualforce page and a custom controller with methods to handle different buttons and events that can occur on the page. What should the developer do to deploy to production?
- A. Create a test class that provides coverage of the Visualforce page.
- B. Create a test page that provides coverage of the Visualforce page.
- C. Create a test page that provides coverage of the custom controller.
- D. Create a test class that provides coverage of the custom controller.
Show answer and explanation ▾
Correct answer: D
Only Apex counts toward code coverage, and deployment to production requires at least 75 percent coverage of Apex. The custom controller holds all the button and event logic, so the developer writes a test class that instantiates the controller and calls those methods. Visualforce markup itself is not covered and needs no test.
Why the other options are wrong:
- A. A Visualforce page carries no code coverage requirement, so covering the page is not the deployment gate.
- B. There is no such thing as a test page. Coverage comes from Apex test classes.
- C. Coverage of the controller is right, but it is produced by a test class, not a page.
Question 26
What is a benefit of using an after insert trigger over using a before insert trigger?
- A. An after insert trigger allows a developer to bypass validation rules when updating fields on the new record.
- B. An after insert trigger allows a developer to insert other objects that reference the new record.
- C. An after insert trigger allows a developer to make a callout to an external service.
- D. An after insert trigger allows a developer to modify fields in the new record without a query.
Show answer and explanation ▾
Correct answer: B
In a before insert trigger the records do not yet have IDs, because they have not been written to the database. An after insert trigger runs once the records are committed and their IDs are populated, so other records that need to reference the new records by ID can be created there. That is the defining benefit.
Why the other options are wrong:
- A. Validation rules run before the after trigger fires and cannot be bypassed by choosing a trigger timing.
- C. Callouts from a trigger require an asynchronous method marked @future(callout=true) or a Queueable, in before or after alike.
- D. Modifying fields on the triggering record without a query and without extra DML is the advantage of a before trigger, not an after trigger.
Question 27
The operation manager at a construction company uses a custom object called Machinery to manage the usage and maintenance of its cranes and other machinery. The manager wants to be able to assign machinery to different constructions jobs, and track the dates and costs associated with each job. More than one piece of machinery can be assigned to one construction job. What should a developer do to meet these requirements?
- A. Create a lookup field on the Construction Job object to the Machinery object.
- B. Create a lookup field on the Machinery object to the Construction Job object.
- C. Create a junction object with Master-Detail Relationship to both the Machinery object and the Construction Job object.
- D. Create a Master-Detail Lookup on the Machinery object to the Construction Job object.
Show answer and explanation ▾
Correct answer: C
A construction job can have several pieces of machinery and a piece of machinery is assigned to several jobs over time, which is a many-to-many relationship. The platform models that with a junction object holding master-detail relationships to both Machinery and Construction Job. The junction record is also the natural place for the dates and costs of each assignment, which is what the manager wants to track.
Why the other options are wrong:
- A. A lookup on Construction Job to Machinery allows only one machine per job, which contradicts the requirement.
- B. A lookup on Machinery to Construction Job ties a machine to a single job and loses the history of earlier assignments along with their dates and costs.
- D. A single master-detail from Machinery to Construction Job is still one-to-many and cannot record a machine on more than one job.
Question 28
Which set of roll-up types are available when creating a roll-up summary field?
- A. COUNT, SUM, MIN, MAX
- B. AVERAGE, SUM, MIN, MAX
- C. SUM, MIN, MAX
- D. AVRAGE, COUNT, SUM, MIN, MAX
Show answer and explanation ▾
Correct answer: A
A roll-up summary field aggregates child records across a master-detail relationship using one of four functions: COUNT, SUM, MIN and MAX. There is no averaging function, and an average has to be derived with a formula that divides a SUM roll-up by a COUNT roll- up.
Why the other options are wrong:
- B. AVERAGE is not an available roll-up type, and omitting COUNT leaves out one that is.
- C. COUNT is missing. It is one of the four supported types.
- D. AVERAGE is not offered regardless of spelling.
Question 29
What is the result of the debug statements in testMethod3 when you create test data using testSetup in below code?
- A. Account0.Phone=333-8781, Account1.Phone=333-8780
- B. Account0.Phone=888-1515, Account1.Phone=999-2525
- C. Account0.Phone=333-8780, Account1.Phone=333-8781
- D. Account0.Phone=888-1515, Account1.Phone=999-1515
Show answer and explanation ▾
Correct answer: C
Account0.Phone=333-8780, Account1.Phone=333- 8781 Records created in a @testSetup method are inserted once and then made available to every test method, and the platform rolls the data back to that setup state before each method runs. So whatever an earlier test method did to the phone numbers is discarded, and testMethod3 sees the original values assigned in the setup loop, which are 333-8780 for the first account and 333-8781 for the second.
Why the other options are wrong:
- A. The values are shown against the wrong accounts. The index suffix follows the loop counter.
- B. 888-1515 and 999-2525 are values set inside other test methods. Those changes are rolled back before this method runs.
- D. These are also values from another test method rather than the setup data, and the second is not even a value that method assigned.
Question 30
How should a developer avoid hitting the governor limits in test methods?
- A. Use @TestVisible on methods that create records.
- B. Use Test.loadData() to load data from a static resource.
- C. Use @IsTest (SeeAllData=true) to use existing data.
- D. Use Test.startTest() to reset governor limits.
Show answer and explanation ▾
Correct answer: D
Test.startTest() gives the test a fresh set of governor limits for the code between it and Test.stopTest(). Setup work performed before startTest, such as creating data, is charged to the first set of limits, so the code actually under test runs with a clean allowance.
Why the other options are wrong:
- A. @TestVisible only exposes private members to tests. It has no effect on limits.
- B. Test.loadData() is a convenient way to create records from a static resource, but the rows it inserts still consume DML limits.
- C. SeeAllData=true grants access to org data. It does not raise or reset any limit.
Question 31
A developer is asked to set a picklist field to `˜Monitor' on any new Leads owned by a subnet of Users. How should the developer implement this request?
- A. Create an after insert Lead trigger.
- B. Create a before insert Lead trigger.
- C. Create a Lead Workflow Rule Field Update.
- D. Create a Lead formula field.
Show answer and explanation ▾
Correct answer: B
The value has to be on the record when it is first saved, and the condition depends on who owns the record, so the logic runs on insert. A before insert trigger can set the picklist directly on the records in Trigger.new with no additional DML, because the records have not been written yet. That makes it the efficient place to stamp a field value during creation.
Why the other options are wrong:
- A. An after insert trigger sees committed records, so changing a field would require a second DML statement on the same records and is wasteful.
- C. A workflow field update also writes after the initial save and triggers a second save cycle. It is the older declarative route and does not match the stated design.
- D. A formula field is calculated on read and cannot be edited or stored, so it cannot set a picklist value.
Question 32
Why would a developer consider using a custom controller over a controller extension?
- A. To increase the SOQL query governor limits.
- B. To implement all of the logic for a page and bypass default Salesforce functionality
- C. To leverage built-in functionality of a standard controller
- D. To enforce user sharing settings and permissions
Show answer and explanation ▾
Correct answer: B
A custom controller replaces the standard controller entirely, so the developer writes all of the logic for the page and none of the default Salesforce record handling applies. An extension, by contrast, exists to add to a controller that is already doing the standard work. Wanting full control and no default behaviour is the reason to choose a custom controller.
Why the other options are wrong:
- A. Governor limits are fixed by the platform. No controller choice raises them.
- C. Leveraging standard controller behaviour is the reason to use an extension, which is the opposite of this choice.
- D. A custom controller runs in system mode by default and ignores user permissions and field level security unless it is declared with sharing.
Question 33
A developer wants to override a button using Visualforce on an object. What is the requirement?
- A. The controller or extension must have a PageReference method.
- B. The standardController attribute must be set to the object.
- C. The action attribute must be set to a controller method.
- D. The object record must be instantiated in a controller or extension.
Show answer and explanation ▾
Correct answer: B
For a Visualforce page to be selectable as an override for a standard button on an object, the page has to be bound to that object, which means its standardController attribute names the object. Without that binding the page does not appear in the override list at all.
Why the other options are wrong:
- A. A PageReference method is useful for redirecting, but it is not what makes a page eligible to override a button.
- C. The action attribute runs a method on page load. It is optional and unrelated to the override requirement.
- D. With a standard controller the record is supplied by the platform, so nothing has to be instantiated in code.
Question 34
A lead object has a custom field Prior_Email__c. The following trigger is intended to copy the current Email into the Prior_Email__c field any time the Email field is changed: Which type of exception will this trigger cause?
- A. A null reference exception
- B. A compile time exception
- C. A DML exception
- D. A limit exception when doing a bulk update
Show answer and explanation ▾
Correct answer: C
Records in Trigger.new during a before trigger are not yet in the database, and Apex forbids running a DML statement against Trigger.new or Trigger.old. Attempting an update inside a before trigger therefore throws a System.SObjectException at run time saying DML cannot operate on trigger.new. In a before trigger the field is simply assigned and the platform saves it, no DML needed.
Why the other options are wrong:
- A. Nothing here dereferences a null. The fields being read are populated.
- B. The code compiles. The restriction is enforced when the DML executes, not by the compiler.
- D. The exception occurs on the very first record. It is not a volume problem and is not avoided by smaller batches.
Question 35
How should a developer create a new custom exception class?
- A. public class CustomException extends Exception{}
- B. CustomException ex = new (CustomException)Exception();
- C. public class CustomException implements Exception{}
- D. (Exception)CustomException ex = new Exception();
Show answer and explanation ▾
Correct answer: A
A custom exception in Apex is declared by extending an existing exception class, and its name must end in Exception. The class body may be left empty because the inherited constructors and methods provide everything needed, so public class CustomException extends Exception{} is the complete declaration.
Why the other options are wrong:
- B. This is not valid Apex syntax, and Exception cannot be instantiated and cast this way.
- C. Exception is a class, not an interface, so it is extended rather than implemented.
- D. The cast is placed before the declaration, which is not valid syntax, and it creates a base Exception rather than a custom one.
Question 36
How can a developer set up a debug log on a specific user?
- A. It is not possible to setup debug logs for users other than yourself.
- B. Ask the user for access to their account credentials, log in as the user and debug the issue.
- C. Create Apex code that logs code actions into a custom object.
- D. Set up a trace flag for the user, and define a logging level and time period for the trace.
Show answer and explanation ▾
Correct answer: D
A trace flag is set for a specific user together with a debug level and a start and end time. While the trace is active the platform writes debug logs for that user's transactions, which is how a developer captures a problem that only reproduces for someone else.
Why the other options are wrong:
- A. Logging other users is fully supported and is the normal way to debug a user-specific issue.
- B. Asking for credentials is a security violation. Login access can be granted, but a trace flag is the correct tool and needs no impersonation.
- C. Writing a custom logging object duplicates a platform feature and still would not capture platform-level debug output.
Question 37
A developer needs to create a Visualforce page that displays Case data. The page will be used by both support reps and support managers. The Support Rep profile does not allow visibility of the Customer_Satisfaction__c field, but the Support Manager profile does. How can the developer create the page to enforce Field Level Security and keep future maintenance to a minimum?
- A. Create one Visualforce Page for use by both profiles.
- B. Use a new Support Manager permission set.
- C. Create a separate Visualforce Page for each profile.
- D. Use a custom controller that has the with sharing keywords.
Show answer and explanation ▾
Correct answer: A
When a Visualforce page renders fields through apex:outputField, apex:inputField or a related list, the platform automatically enforces field level security for the running user. The Customer_Satisfaction__c field simply does not render for a support rep and does render for a manager, so one page serves both profiles and there is nothing extra to maintain.
Why the other options are wrong:
- B. A permission set changes who can see the field. It does not decide how the page is built, and the profiles already differ correctly.
- C. Two pages doubles the maintenance, which is exactly what the requirement rules out.
- D. with sharing enforces record level sharing, not field level security, so it does not address the requirement.
Question 38
A developer wrote a unit test to confirm that a custom exception works properly in a custom controller, but the test failed due to an exception being thrown. Which step should the developer take to resolve the issue and properly test the exception?
- A. Use try/catch within the unit test to catch the exception.
- B. Use the finally bloc within the unit test to populate the exception.
- C. Use the database methods with all or none set to FALSE.
- D. Use Test.isRunningTest() within the custom controller.
Show answer and explanation ▾
Correct answer: A
A test that calls code which throws will fail unless the test handles the throw. Wrapping the call in try/catch lets the test catch the custom exception, assert on its type or message, and pass. The catch block is what turns an expected exception into a verified behaviour rather than a test failure.
Why the other options are wrong:
- B. A finally block always runs but does not stop the exception propagating, so the test still fails.
- C. Setting allOrNone to false suppresses DML failures on individual records. It does not affect an exception thrown by controller logic.
- D. Branching on Test.isRunningTest() to dodge the exception means the exception path is never actually tested.
Question 39
Which SOQL query successfully returns the Accounts grouped by name?
- A. SELECT Type, Max(CreatedDate) FROM Account GROUP BY Name
- B. SELECT Name, Max(CreatedDate) FROM Account GROUP BY Name
- C. SELECT Id, Type, Max(CreatedDate) FROM Account GROUP BY Name
- D. SELECT Type, Name, Max(CreatedDate) FROM Account GROUP BY Name LIMIT 5
Show answer and explanation ▾
Correct answer: B
When a SELECT list contains an aggregate function, every non-aggregated field in that list must also appear in the GROUP BY clause. Selecting Name alongside MAX(CreatedDate) and grouping by Name satisfies that rule, so the query runs and returns one row per account name.
Why the other options are wrong:
- A. Type is selected but not grouped, so the query is rejected.
- C. Id is selected but not grouped, and Type is too. Selecting Id in an aggregate query is also meaningless because it is unique per record.
- D. Type is selected but not included in the GROUP BY. The LIMIT clause is legal but does not fix the grouping error.
Question 40
A Platform Developer needs to implement a declarative solution that will display the most recent Closed Won date for all Opportunity records associated with an Account. Which field is required to achieve this declaratively?
- A. Roll-up summary field on the Opportunity object
- B. Cross-object formula field on the Opportunity object
- C. Roll-up summary field on the Account object
- D. Cross-object formula field on the Account object
Show answer and explanation ▾
Correct answer: C
The value has to appear on the Account and be derived from its Opportunities, so the field belongs on the parent. Account to Opportunity is one of the standard relationships that supports a roll-up summary despite being a lookup, and a MAX roll-up on Close Date filtered to Closed Won returns the most recent Closed Won date declaratively.
Why the other options are wrong:
- A. A roll-up lives on the parent object. Placing it on Opportunity would be aggregating the wrong direction.
- B. A cross-object formula on Opportunity reaches up to the Account. It cannot aggregate across sibling records and the result would be on the wrong object.
- D. A cross-object formula on Account cannot reach down to child Opportunities. Formulas only traverse upward to a parent.
Question 41
What is the data type returned by the following SOSL search? [FIND `˜Acme*' IN NAME FIELDS RETURNING Account, Opportunity];
- A. List<List<Account>, List<Opportunity>>
- B. Map<sObject, sObject>
- C. List<List<sObject>>
- D. Map<Id, sObject>
Show answer and explanation ▾
Correct answer: C
A SOSL search can return records from several objects at once, so the result is a list of lists of sObjects. The outer list has one entry per object named in the RETURNING clause, in the order they were listed, and each inner list holds the matching records for that object.
Why the other options are wrong:
- A. Apex generics do not accept two type parameters on a List, so this is not a valid type.
- B. A SOSL search returns lists of results, not a mapping from one record to another.
- D. SOSL does not key its results by ID. That shape would come from constructing a Map in code.
Question 42
For which example task should a developer use a trigger rather than a workflow rule?
- A. To set the Name field of an expense report record to Expense and the Date when it is saved
- B. To send an email to a hiring manager when a candidate accepts a job offer
- C. To notify an external system that a record has been modified
- D. To set the primary Contact on an Account record when it is saved
Show answer and explanation ▾
Correct answer: D
Setting the primary Contact on the Account means writing to a different record from the one being saved, using data looked up from related records. A workflow rule field update can only change fields on the record that fired it or, in the single special case of master- detail, on its parent. Populating a lookup to a Contact from Account logic therefore needs Apex.
Why the other options are wrong:
- A. Setting a field on the record being saved is exactly what a workflow field update does.
- B. Sending an email is a standard workflow email alert action.
- C. Notifying an external system is what a workflow outbound message is for.
Question 43
Which feature should a developer use to update an inventory count on related Product records when the status of an Order is modified to indicate it is fulfilled?
- A. Process Builder process
- B. Lightning component
- C. Visualforce page
- D. Workflow rule
Show answer and explanation ▾
Correct answer: A
Process Builder can start from the Order, evaluate the change of status to fulfilled, walk the relationship to the related Product records and update a field on them. It is the declarative tool that handles both the trigger condition and the update of related records.
Why the other options are wrong:
- B. A Lightning component renders user interface. It runs only when a user opens it, so nothing happens automatically on the status change.
- C. A Visualforce page is likewise a user interface and does not respond to a record update.
- D. A Workflow Rule field update cannot write to related Product records.
Question 44
A developer has JavaScript code that needs to be called by controller functions in multiple Aura components by extending a new abstract component. Which resource in the abstract Aura component bundle allows the developer to achieve this?
- A. helper.js
- B. controller.js
- C. superRender.js
- D. renderer.js
Show answer and explanation ▾
Correct answer: A
The helper resource is where shared JavaScript logic belongs. Helper methods are callable from the controller of the component and, because helpers are inherited when a component extends an abstract component, the same functions become available to every component that extends it. That is exactly the reuse the developer wants.
Why the other options are wrong:
- B. The controller handles events for its own component and is not the place for logic meant to be shared across components.
- C. There is no superRender.js resource. A renderer can call superRender(), but that is a method rather than a file.
- D. The renderer customises how the component is drawn in the DOM, not where shared business logic lives.
Question 45
Which option should a developer use to create 500 Accounts and make sure that duplicates are not created for existing Account Sites?
- A. Sandbox template
- B. Data Loader
- C. Data Import Wizard
- D. Salesforce-to-Salesforce
Show answer and explanation ▾
Correct answer: C
The Data Import Wizard handles up to 50,000 records, so 500 Accounts is well within range, and it offers built-in duplicate matching so existing records can be matched rather than duplicated. That combination of volume and duplicate prevention is what the requirement asks for.
Why the other options are wrong:
- A. A sandbox template controls which data a Full or Partial sandbox copies. It does not import records.
- B. Data Loader handles far larger volumes but has no duplicate matching of its own. Preventing duplicates would require an External ID and an upsert.
- D. Salesforce-to-Salesforce shares records between two orgs. It is not an import tool for a spreadsheet of accounts.
Question 46
What is the debug output of the following Apex code? Decimal theValue; System.debug(theValue);
- A. 0.0
- B. null
- C. Undefined
- D. 0
Show answer and explanation ▾
Correct answer: B
Apex initialises every variable that is declared without an assignment to null, and that applies to primitives as well as objects. A Decimal declared and never set is therefore null, and debugging it prints null.
Why the other options are wrong:
- A. Apex does not default numeric types to zero. That is Java behaviour for primitives.
- C. Undefined is a JavaScript concept. Apex has no such value.
- D. Again, there is no numeric default. The variable holds null.
Question 47
Which type of code represents the Model in the MVC architecture when using Apex and Visualforce pages?
- A. A Controller Extension method that saves a list of Account records
- B. Custom JavaScript that processes a list of Account records
- C. A list of Account records returned from a Controller Extension method
- D. A Controller Extension method that uses SOQL to query for a list of Account records
Show answer and explanation ▾
Correct answer: C
The Model is the data itself. A list of Account records returned from a controller extension is exactly that: the sObject data the page will render. The methods that fetch or save it are Controller code, and the page markup is the View.
Why the other options are wrong:
- A. A method that saves records is logic acting on the data, which places it in the Controller.
- B. JavaScript that processes records runs in the View layer and is presentation logic.
- D. A method that queries is Controller code. The Model is the data it returns, not the method.
Question 48
Requirements state that a child record is deleted when its parent is deleted, and a child can be moved to a different parent when necessary. Which type of relationship should be built between the parent and child objects in Schema builder to support these requirements?
- A. Master-Detail relationship
- B. Child relationship
- C. Lookup relationship from the parent to the child
- D. Lookup relationship from the child to the parent
Show answer and explanation ▾
Correct answer: A
A master-detail relationship gives cascade delete, so removing the parent deletes its children, which is the first requirement. The second is met by enabling the Allow reparenting option on the relationship, which permits the child to be moved to a different parent. Both behaviours come from a master-detail with that option set.
Why the other options are wrong:
- B. There is no relationship type called a child relationship. Child relationship is the name given to the reverse reference.
- C. Relationship fields are created on the child pointing at the parent, not the other way round.
- D. A lookup does not cascade delete. Deleting the parent leaves the child with an empty lookup, or is blocked.
Question 49
Which tag should a developer include when styling from external CSS is required in a Visualforce page?
- A. apex:includeStyles
- B. apex:includeScript
- C. apex:require
- D. apex:stylesheet
Show answer and explanation ▾
Correct answer: D
The <apex:stylesheet> tag adds a link to an external CSS file in the generated page, which is how a Visualforce page pulls in styling held in a static resource or another external location.
Why the other options are wrong:
- A. There is no apex:includeStyles tag.
- B. apex:includeScript adds a JavaScript file, not a stylesheet.
- C. apex:require does not exist. The Lightning tag ltng:require is a different framework.
Question 50
Managed Packages can be created in which type of org?
- A. Developer Sandbox
- B. Partial Copy Sandbox
- C. Unlimited Edition
- D. Developer Edition
Show answer and explanation ▾
Correct answer: D
A managed package must be created in a Developer Edition org. That org holds the namespace the package is registered against and can contain exactly one managed package, which is why development for AppExchange starts from a Developer Edition org rather than a sandbox.
Why the other options are wrong:
- A. Sandboxes cannot create managed packages. They also cannot register a namespace.
- B. The same applies to a Partial Copy sandbox.
- C. Unlimited Edition is a production edition. Managed package development does not happen there.
Get the complete Salesforce Certified Platform Developer I bank
These 50 questions are roughly 17% of the bank. The full pack has 439 real Salesforce Certified Platform Developer I questions, each with the same depth of explanation, plus a questions-only PDF for timed practice and free updates forever.
View the full Salesforce Certified Platform Developer I question bank →