# Free PDII practice questions

> 10 free PDII practice questions with the correct answer and an explanation.

Page: https://devopscodelab.com/exams/salesforce-pdii/free-practice-questions/
Practice exams: https://devopscodelab.com/exams/salesforce-pdii/

### Question 1 of 10

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?

- A. Without sharing from InvoiceService, because sharing keywords only apply to the outermost class of the transaction
- B. With sharing from InvoiceService, and without sharing from the Aura-enabled class because that caller omits the keyword
- C. Without sharing in both cases, because inherited sharing defers to the system context of the Apex runtime
- D. With sharing in both cases, because each caller enforces sharing and inherited sharing adopts the caller's mode

**Answer:** D

**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

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?

- A. Configure an outbound message from a record-triggered flow on Opportunity update
- B. Create a PushTopic on Opportunity and subscribe through the Streaming API in Apex
- C. Enable Change Data Capture for Opportunity and subscribe through the Pub/Sub API
- D. Write an after update trigger that publishes a custom platform event per change

**Answer:** C

**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 (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.)

- A. Wrap the trigger body in Database.setSavepoint() and roll back to it, which causes the platform to redeliver the events
- B. Decrease the batch size of the event subscription to 1 so that the platform automatically retries every failed event
- C. Use FOR UPDATE in the trigger's SOQL so the event trigger waits indefinitely until the competing lock is released
- D. Call EventBus.TriggerContext.currentContext().setResumeCheckpoint(replayId) after each processed event so a restart resumes after it
- E. Throw EventBus.RetryableException so the batch of events is redelivered later, up to the platform retry limit

**Answer:** D, E

**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

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?

- A. Pass System.enqueueJob() an AsyncOptions object with a DuplicateSignature from a stable key and MinimumQueueableDelayInMinutes = 5
- B. Implement Database.Stateful on the Queueable so that the platform detects duplicate chains and delays each link by its configured interval
- C. Use a static Boolean in the Queueable to block the second click and call Thread.sleep(300000) before enqueueing the next job
- D. Check System.isQueueable() before enqueueing and call System.scheduleBatch() with a 5-minute interval to throttle the following link

**Answer:** A

**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

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?

- A. import { save } from 'c/caseCtrl'; handleClick() { save(this.recordId).then(() => this.dispatchEvent(new CustomEvent('toast', { detail: 'Saved' }))); }
- B. import save from '@salesforce/apex/CaseCtrl.save'; handleClick() { save({ caseId: this.recordId }).then(() => this.dispatchEvent(new ShowToastEvent({ title: 'Saved', variant: 'success' }))); }
- C. import save from '@salesforce/apex/CaseCtrl.save'; handleClick() { const r = save({ caseId: this.recordId }); if (r.success) { alert('Saved'); } }
- D. import save from '@salesforce/apex/CaseCtrl.save'; @wire(save, { caseId: '$recordId' }) result; handleClick() { this.result.refresh(); this.dispatchEvent(new ShowToastEvent({ title: 'Saved' })); }

**Answer:** B

**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

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?

- A. bubbles: true, composed: false, with the parent re-dispatching the event to the grandparent
- B. bubbles: false, composed: true, which crosses shadow boundaries without bubbling up the tree
- C. bubbles: false, composed: false, with the grandparent listening on the child via a template ref
- D. bubbles: true, composed: true, letting the event cross every shadow boundary to the document

**Answer:** A

**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

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?

- A. RunAllTestsInOrg
- B. NoTestRun
- C. RunSpecifiedTests
- D. RunLocalTests

**Answer:** D

**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

A developer uses the Apex Replay Debugger in VS Code to investigate a production issue reproduced in a sandbox. What is required?

- A. A debug log captured with Apex Code at FINEST, then replayed with 'SFDX: Launch Apex Replay Debugger with Current File'
- B. An active debugging session created in Setup, with Apex Interactive Debugger licenses purchased for the production org and assigned to the developer
- C. A checkpoint set in the Developer Console on the relevant line, then a heap dump downloaded and opened in VS Code
- D. A trace flag on the Automated Process user with the Database log level set to DEBUG and Workflow set to FINER

**Answer:** A

**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

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?

- A. Rebuild the Contact data load to use Bulk API in serial mode with a batch size of 10,000 records
- B. Add FOR UPDATE to every query on Contact so updates wait for the Account lock to become available
- C. Change the Contact sharing model to Controlled by Parent so that saves skip the sharing recalculation step
- D. Spread the Contacts across several parent Accounts so no Account holds more than about 10,000 children

**Answer:** D

**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

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?

- A. Formula fields are always indexed automatically, so the query must use a different field
- B. Custom indexes on fields of objects with over 5 million rows are never allowed by Salesforce
- C. The formula must be converted to a roll-up summary, which is indexed by default on any object
- D. A formula field that references a related object or is non-deterministic cannot be indexed

**Answer:** D

**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.

Ready for a timed run? Take the free 15-question PDII mini exam: https://devopscodelab.com/app/exams/salesforce-pdii/mini/

DevOpsCode Lab is not affiliated with Salesforce. PDII and related names are trademarks of their owners. We write every question ourselves; these are not real exam questions.
