SPDI
Free SPDI practice questions
10 questions from our SPDI 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, Developer Fundamentals
An @AuraEnabled method returns Contact records to a Lightning web component. Users without read access to the Contact SSN__c field must receive the records with that field silently removed rather than an error. Which approach should the developer use?
- APass the queried list through Security.stripInaccessible(AccessType.READABLE, records) and return getRecords() Correct answer
- BQuery the records WITH USER_MODE so that inaccessible fields are removed from each returned record automatically
- CCheck Schema.sObjectType.Contact.isAccessible() before the query and return the records if it is true
- DDeclare the controller class with sharing so field-level security is applied to every queried field
Answer and explanation: Security.stripInaccessible removes fields the user cannot read from the records and returns a sanitized list through getRecords(), without throwing an exception. WITH USER_MODE enforces field-level security but throws an exception when an inaccessible field is in the query instead of silently removing it. The with sharing keyword enforces record sharing only, never field-level security. An object-level isAccessible check does not evaluate individual field permissions.
Question 2 of 10, Developer Fundamentals
A new developer asks why Apex code is subject to governor limits such as a cap on SOQL queries per transaction. Which explanation is accurate?
- ALimits keep each org within the data storage allocation it purchased, so inserts stop before the org exceeds its storage quota
- BMany orgs share the same servers and database in the multitenant architecture, so limits stop one tenant's code from monopolizing them Correct answer
- CLimits keep each user within the 24-hour API request entitlement licensed to the org, so Apex calls count against the same allowance
- DLimits make sure each transaction finishes before the session timeout set in Session Settings expires for the running user's browser
Answer and explanation: Governor limits exist because the platform is multitenant: orgs share infrastructure, so the runtime caps what any single transaction can consume. Data storage is enforced separately and does not throttle SOQL counts. The daily API request allowance applies to external API calls, not to Apex statements running inside a transaction. Session timeout controls user inactivity and has nothing to do with per-transaction resource caps.
Question 3 of 10, Process Automation and Logic
A method builds a dynamic SOQL query by concatenating a search term that a user types into a Lightning web component. Which change best prevents SOQL injection?
- AConvert the search term to lowercase with toLowerCase() before concatenating it into the query
- BWrap Database.query in a try-catch block so malformed injected queries return an empty list
- CRun the dynamic query in a without sharing class so the query cannot reach restricted records
- DUse a bind variable such as WHERE Name = :searchTerm, or Database.queryWithBinds with a bind map Correct answer
Answer and explanation: Bind variables (and Database.queryWithBinds with a bind map) pass user input as values rather than query text, so it cannot change the query's structure; String.escapeSingleQuotes is a fallback when concatenation is unavoidable. Running without sharing widens access and makes injection more dangerous. Changing letter case does not neutralize quotes or operators. Catching exceptions hides errors but does not stop a well-formed injected clause from returning extra data.
Question 4 of 10, Process Automation and Logic
A trigger on Contact must set a custom field Region__c from the related Account's BillingState whenever a Contact is inserted. Data loads of up to 200 records per chunk are common. Which approach follows Apex best practices?
- AIn an after insert trigger, call a @future method per Contact that queries its Account and updates Region__c asynchronously
- BIn a before insert trigger, query the Account for each Contact inside the loop over Trigger.new and assign Region__c directly
- CIn an after insert trigger, collect the Contacts in a list, set Region__c from a query per record, and call update on that list
- DIn a before insert trigger, collect AccountIds in a Set, query once into a Map<Id, Account>, then set Region__c from the map Correct answer
Answer and explanation: A before insert trigger can change field values on Trigger.new without extra DML, and collecting Ids into a Set with one query into a Map keeps the trigger bulkified. Querying inside the loop would hit the 100 SOQL query limit on a 200-record chunk. An after insert approach needs an extra DML statement and still queries per record. Calling a future method per record wastes async capacity, would exceed the limit of 50 future calls per transaction, and delays the value.
Question 5 of 10, Process Automation and Logic
A report needs all Task records whose related record (the What field) is an Opportunity. Which SOQL query returns them?
- ASELECT Id, Subject FROM Opportunity.Tasks WHERE What.Type = 'Opportunity'
- BSELECT Id, Subject FROM Task WHERE WhatId LIKE 'Opportunity%' ORDER BY CreatedDate
- CSELECT Id, Subject FROM Task WHERE What.Type = 'Opportunity' Correct answer
- DSELECT Id, Subject FROM Task WHERE What = 'Opportunity' AND IsClosed = false
Answer and explanation: WhatId is a polymorphic relationship, and filtering on What.Type returns Tasks whose related record is of the given object type. Record Ids start with a key prefix such as 006, not the object name, so a LIKE filter on the name never matches. What is a relationship, so it cannot be compared to a string, and the open-task filter changes the result. A relationship name such as Opportunity.Tasks cannot be used in FROM; child records are queried with a subquery.
Question 6 of 10, User Interface
A Visualforce page uses the standard controller for Account and needs one additional action method that recalculates a custom score. Which approach requires the least code while keeping standard save and edit behavior?
- AReplace the page with a StandardSetController-based list controller and add the method
- BWrite a controller extension whose constructor accepts ApexPages.StandardController Correct answer
- CWrite a custom controller that re-implements save and edit and adds the new method
- DWrite an Apex trigger on Account that recalculates the score on every update event
Answer and explanation: A controller extension adds functionality to a standard controller while inheriting its built-in actions such as save and edit; its constructor receives an ApexPages.StandardController. A custom controller replaces the standard controller entirely, so standard behavior would have to be rewritten. A trigger fires on every update, not on a user action from the page. A StandardSetController is for working with sets of records in list pages and does not fit a single-record page.
Question 7 of 10, User Interface
A child Lightning web component must notify its parent that a row was selected and pass the selected record Id. Which code should the child use?
- Athis.parentNode.setAttribute('rowselect', this.recordId);
- Bpublish(this.messageContext, ROW_SELECTED_CHANNEL, { recordId: this.recordId });
- Cthis.template.querySelector('c-parent').rowselect(this.recordId);
- Dthis.dispatchEvent(new CustomEvent('rowselect', { detail: this.recordId })); Correct answer
Answer and explanation: Child-to-parent communication in LWC uses a CustomEvent dispatched by the child, with data in the detail property; the parent listens with onrowselect. A child cannot query its parent through this.template, which only reaches the component's own shadow tree. Lightning Message Service works across the DOM but is unnecessary overhead for a direct parent-child relationship. Setting attributes on the parent node is not a supported communication pattern.
Question 8 of 10, User Interface
A component wires getRecord for a Contact and must read the Email value safely in JavaScript. EMAIL_FIELD is imported from @salesforce/schema/Contact.Email. Which code is correct?
- Areturn this.contact.fields.Email;
- Breturn this.contact.data.Email.value.toString();
- Creturn getFieldValue(this.contact.data, EMAIL_FIELD); Correct answer
- Dreturn this.contact.Email; after checking that this.contact is defined
Answer and explanation: getFieldValue from lightning/uiRecordApi takes the provisioned data and an imported field reference and returns the value safely, handling the nested record structure. A wired property contains data and error, not fields directly. Data from getRecord is under data.fields, so data.Email does not exist, and calling toString on it would throw while data is still undefined. The wired property has no fields key at the top level.
Question 9 of 10, Testing, Debugging, and Deployment. Choose 2.
Which two statements about the @testSetup annotation in an Apex test class are true? (Choose two.)
- A@testSetup methods also work in classes annotated with @isTest(SeeAllData=true)
- BRecords created in a @testSetup method are committed to the org after the test run finishes
- CEach test method gets the original records, so changes made by one test method are not seen by another Correct answer
- DA test class can contain only one @testSetup method Correct answer
- ERecords created in a @testSetup method are rolled back and recreated for each test method in the class
Answer and explanation: A test class can have only one @testSetup method, and the records it creates are available to every test method; each test method works with a fresh copy because changes are rolled back after each method. @testSetup is not supported in classes that use SeeAllData=true. Test data, including setup data, is never committed to the org. The setup method runs once per class, not once per test method, which is why it saves execution time.
Question 10 of 10, Testing, Debugging, and Deployment
A test method inserts 200 Opportunities and then calls a method that enqueues a Queueable job. The assertions that follow fail because the job's changes are not visible. What should the developer do?
- AWrap the code that enqueues the job between Test.startTest() and Test.stopTest() and assert after stopTest Correct answer
- BAnnotate the test method with @isTest(SeeAllData=true) so that the job can read the inserted records
- CCall System.enqueueJob() a second time inside the test so the platform processes the queue sooner
- DAdd System.runAs() around the enqueue call so the job runs with the permissions of an admin user
Answer and explanation: Asynchronous work enqueued between Test.startTest() and Test.stopTest() runs synchronously when stopTest() is called, so assertions placed after it see the results. SeeAllData only exposes existing org data and does not make async jobs execute. System.runAs changes the running user and record sharing, not async execution timing. Enqueuing the job again just adds another job without forcing either to run before the assertions.