PDII
Free PDII practice questions
10 questions from our PDII practice tests, each with the correct answer and a written explanation. Read them with the answers shown, or switch to quiz mode and answer first.
Question 1 of 10, Advanced Developer Fundamentals
A developer writes an Apex class declared 'public with sharing class InvoiceService' that calls a method in 'public inherited sharing class InvoiceSelector'. The selector is also invoked directly from an Aura-enabled method in a class that has no sharing keyword at all. Which sharing context does the selector run in for each caller?
- AWithout sharing from InvoiceService, because sharing keywords only apply to the outermost class of the transaction
- BWith sharing from InvoiceService, and without sharing from the Aura-enabled class because that caller omits the keyword
- CWithout sharing in both cases, because inherited sharing defers to the system context of the Apex runtime
- DWith sharing in both cases, because each caller enforces sharing and inherited sharing adopts the caller's mode Correct answer
Answer and explanation: An inherited sharing class runs in the sharing mode of its caller. InvoiceService is with sharing, and an Apex controller with @AuraEnabled methods and no sharing keyword runs with sharing by default when invoked from Lightning, so the selector enforces sharing in both paths. Inherited sharing never means system context, an omitted keyword on a Lightning entry point does not imply without sharing, and sharing keywords apply per class rather than only to the outermost class.
Question 2 of 10, Process Automation, Logic, and Integration
An integration must react in near real time to every change of Opportunity Stage made by any user, API or automation, and the external subscriber should receive the changed fields with a header that identifies the operation. Which feature requires the LEAST custom code?
- AConfigure an outbound message from a record-triggered flow on Opportunity update
- BCreate a PushTopic on Opportunity and subscribe through the Streaming API in Apex
- CEnable Change Data Capture for Opportunity and subscribe through the Pub/Sub API Correct answer
- DWrite an after update trigger that publishes a custom platform event per change
Answer and explanation: Change Data Capture publishes change events with a ChangeEventHeader (entity, change type, changed fields) for every create, update, delete and undelete with no code, and Pub/Sub API is the recommended subscription channel. A trigger-published event requires custom code, outbound messages are SOAP-based and send whole field sets without a change header, and PushTopics are a legacy feature that is not recommended for new work.
Question 3 of 10, Process Automation, Logic, and Integration. Choose 2.
A developer writes an Apex trigger on a platform event, Shipment_Update__e. The trigger occasionally fails because a downstream record is locked by another process. Which two techniques let the trigger recover without losing events? (Choose two.)
- AWrap the trigger body in Database.setSavepoint() and roll back to it, which causes the platform to redeliver the events
- BDecrease the batch size of the event subscription to 1 so that the platform automatically retries every failed event
- CUse FOR UPDATE in the trigger's SOQL so the event trigger waits indefinitely until the competing lock is released
- DCall EventBus.TriggerContext.currentContext().setResumeCheckpoint(replayId) after each processed event so a restart resumes after it Correct answer
- EThrow EventBus.RetryableException so the batch of events is redelivered later, up to the platform retry limit Correct answer
Answer and explanation: EventBus.RetryableException asks the platform to resend the events in a later trigger invocation, and setResumeCheckpoint records the last successfully processed event so a retry or restart resumes after it. Rolling back to a savepoint does not trigger redelivery, FOR UPDATE waits only up to about 10 seconds before throwing, and a smaller batch size alone does not cause automatic retries.
Question 4 of 10, Process Automation, Logic, and Integration
A Queueable job processes records and enqueues itself to continue with the next chunk. The architect wants to avoid two copies of the chain running concurrently if a user clicks the start button twice, and to add a 5-minute delay between links. Which approach is supported?
- APass System.enqueueJob() an AsyncOptions object with a DuplicateSignature from a stable key and MinimumQueueableDelayInMinutes = 5 Correct answer
- BImplement Database.Stateful on the Queueable so that the platform detects duplicate chains and delays each link by its configured interval
- CUse a static Boolean in the Queueable to block the second click and call Thread.sleep(300000) before enqueueing the next job
- DCheck System.isQueueable() before enqueueing and call System.scheduleBatch() with a 5-minute interval to throttle the following link
Answer and explanation: System.enqueueJob accepts AsyncOptions, where a QueueableDuplicateSignature prevents enqueueing a job with the same signature and MinimumQueueableDelayInMinutes delays execution (up to 10 minutes). isQueueable only reports context and scheduleBatch is for batch classes, statics do not span separate user transactions and Apex has no sleep, and Database.Stateful applies to batch Apex only.
Question 5 of 10, User Interface
An LWC must call a non-cacheable Apex method that updates a record when a button is clicked, then show a success toast. Which code is correct?
- Aimport { save } from 'c/caseCtrl'; handleClick() { save(this.recordId).then(() => this.dispatchEvent(new CustomEvent('toast', { detail: 'Saved' }))); }
- Bimport save from '@salesforce/apex/CaseCtrl.save'; handleClick() { save({ caseId: this.recordId }).then(() => this.dispatchEvent(new ShowToastEvent({ title: 'Saved', variant: 'success' }))); } Correct answer
- Cimport save from '@salesforce/apex/CaseCtrl.save'; handleClick() { const r = save({ caseId: this.recordId }); if (r.success) { alert('Saved'); } }
- Dimport save from '@salesforce/apex/CaseCtrl.save'; @wire(save, { caseId: '$recordId' }) result; handleClick() { this.result.refresh(); this.dispatchEvent(new ShowToastEvent({ title: 'Saved' })); }
Answer and explanation: Methods that perform DML are called imperatively and return a promise; showing a toast uses ShowToastEvent after the promise resolves. Wiring a DML method fails because wired methods must be cacheable, Apex methods are imported from @salesforce/apex rather than c/ modules, and the imperative call returns a promise rather than a result object.
Question 6 of 10, User Interface
A child LWC dispatches an event that must be handled by a grandparent component that contains the parent in its template, but not escape beyond the grandparent's shadow root. Which event configuration is appropriate?
- Abubbles: true, composed: false, with the parent re-dispatching the event to the grandparent Correct answer
- Bbubbles: false, composed: true, which crosses shadow boundaries without bubbling up the tree
- Cbubbles: false, composed: false, with the grandparent listening on the child via a template ref
- Dbubbles: true, composed: true, letting the event cross every shadow boundary to the document
Answer and explanation: An event with bubbles true and composed false stays within the parent's shadow tree, so the parent must handle it and dispatch a new event to reach the grandparent, which keeps the event contained. bubbles and composed true leaks the event across all boundaries, bubbles false with composed true is not a useful configuration, and the grandparent cannot reference elements inside the parent's shadow tree.
Question 7 of 10, Testing, Debugging, and Deployment
A developer deploys Apex classes to production with the Salesforce CLI and does not pass a --test-level flag. Which test level does the platform apply by default?
- ARunAllTestsInOrg
- BNoTestRun
- CRunSpecifiedTests
- DRunLocalTests Correct answer
Answer and explanation: When Apex is included in a production deployment and no test level is given, RunLocalTests is used, running every test except those from installed managed and unlocked packages. RunAllTestsInOrg must be requested explicitly, RunSpecifiedTests requires named test classes, and NoTestRun is not permitted for production deployments that contain Apex.
Question 8 of 10, Testing, Debugging, and Deployment
A developer uses the Apex Replay Debugger in VS Code to investigate a production issue reproduced in a sandbox. What is required?
- AA debug log captured with Apex Code at FINEST, then replayed with 'SFDX: Launch Apex Replay Debugger with Current File' Correct answer
- BAn active debugging session created in Setup, with Apex Interactive Debugger licenses purchased for the production org and assigned to the developer
- CA checkpoint set in the Developer Console on the relevant line, then a heap dump downloaded and opened in VS Code
- DA trace flag on the Automated Process user with the Database log level set to DEBUG and Workflow set to FINER
Answer and explanation: Apex Replay Debugger replays a debug log in VS Code; it requires a log captured with Apex Code at FINEST and is started from the log or current file. The Interactive Debugger is a separate paid feature, checkpoints and heap dumps are a Developer Console feature, and Database/Workflow levels do not provide the needed Apex detail.
Question 9 of 10, Performance
An org has one Account named 'Unassigned' that owns 400,000 Contacts. Updates to Contacts frequently fail with UNABLE_TO_LOCK_ROW and sharing recalculations are slow. What is the BEST remediation?
- ARebuild the Contact data load to use Bulk API in serial mode with a batch size of 10,000 records
- BAdd FOR UPDATE to every query on Contact so updates wait for the Account lock to become available
- CChange the Contact sharing model to Controlled by Parent so that saves skip the sharing recalculation step
- DSpread the Contacts across several parent Accounts so no Account holds more than about 10,000 children Correct answer
Answer and explanation: This is account data skew; spreading children so that no parent has more than roughly 10,000 records reduces parent locking and sharing recalculation time. FOR UPDATE adds more locking, Controlled by Parent ties Contact access to the skewed Account and does not remove the lock contention, and serial mode only reduces concurrency and still leaves the skew.
Question 10 of 10, Performance
Queries on a custom object with 8 million rows filter on External_Status__c, a formula field that references a related object's field. The query is not selective. Why can't a custom index help here?
- AFormula fields are always indexed automatically, so the query must use a different field
- BCustom indexes on fields of objects with over 5 million rows are never allowed by Salesforce
- CThe formula must be converted to a roll-up summary, which is indexed by default on any object
- DA formula field that references a related object or is non-deterministic cannot be indexed Correct answer
Answer and explanation: Salesforce can index only deterministic formula fields; formulas referencing related object fields (cross-object) or using dynamic dates are non-deterministic and cannot be indexed. Formulas are not automatically indexed, large objects can have custom indexes, and roll-up summaries are not indexed by default.