Total 202 Questions
Last Updated On :
Preparing with Salesforce-Platform-Developer-II practice test is essential to ensure success on the exam. This Salesforce SP25 test allows you to familiarize yourself with the Salesforce-Platform-Developer-II exam questions format and identify your strengths and weaknesses. By practicing thoroughly, you can maximize your chances of passing the Salesforce certification spring 2025 release exam on your first attempt. Surveys from different platforms and user-reported pass rates suggest Salesforce-Platform-Developer-II practice exam users are ~30-40% more likely to pass.
A developer needs to store variables to control the style and behavior of a Lightning Web Component. Which feature can be used to ensure that the variables are testable in both Production and all Sandboxes?
A. Custom setting
B. Custom object
C. Custom variable
D. Custom metadata
β
Explanation:
The question is asking for a way to store configuration variables (for styling or behavior control in LWC) that are:
β Testable in Production and all Sandboxes
β Consistent across environments
β Deployable using change sets or metadata tools
The best option that meets all of these requirements is Custom Metadata.
π Why Custom Metadata is the Right Choice
β Testable: Custom metadata can be queried in Apex and used in tests without requiring dynamic creation of records.
β Deployable: Can be packaged and moved between sandboxes and production via change sets, metadata API, or unlocked packages.
β Accessible in Apex, LWC (via Apex), and flows.
β Does not count against data storage limits.
β Ideal for storing configuration that controls logic or styling.
Example Use Case:
Store a flag like isDarkModeEnabled = true, or a color value buttonColor = "#FF0000" in custom metadata, and access it in LWC through an Apex method.
β Why Other Options Are Incorrect
A. Custom Setting
β₯ Limited support in new Salesforce development (legacy).
β₯ Hierarchy custom settings can be user/profile-specific, but not deployable with data via change sets easily.
β₯ Not recommended for org-wide config that needs to be versioned and deployed between environments.
B. Custom Object
β₯ Meant for business data, not configuration.
β₯ Requires data creation in every environment manually or via scripts.
β₯ Not ideal for testing or consistent deployment of config settings.
C. Custom Variable
β₯ Not a real Salesforce feature. There is no such concept as "Custom Variable" in Salesforce metadata.
π Reference Documentation
β Custom Metadata Types Overview
β Custom Metadata vs. Custom Settings
β Deploying Custom Metadata
A company has code to update a Request and Request Lines and make a callout to
their external ERP system's REST endpoint with the updated records.
The callousUtil.makeRestCallout fails with a "You have uncommitted work pending. Please
commit or rollback before calling cutβ error.
What should be done to address the problem?
A. Change the callousUtil makeRestCallout to an @InvocsblsMethod method.
B. Remove the Database. setSavepoint and Database. rollback.
C. Change the CallousUtill .makeRestCallout to an @future method.
β
Explanation:
The error message:
β₯ "You have uncommitted work pending. Please commit or rollback before calling out"
...indicates that a DML operation (like insert/update) was performed before an HTTP callout, which is not allowed in synchronous Apex.
π§ Why This Happens:
Apex enforces a "DML before callout" restriction in synchronous transactions.
In your code:
β₯ You perform insert operations for reqs and reqLines.
β₯ Then you make a callout using CalloutUtil.makeRestCallout(...).
β₯ This causes the runtime to throw the error because uncommitted DML has occurred before the callout.
β
How @future Helps
By marking the callout method as @future(callout=true), you:
β₯ Move the callout logic to an asynchronous context.
β₯ Avoid the DML-before-callout restriction.
β₯ Allow the synchronous part to finish (i.e., insert the records), and then the callout is made separately after the transaction completes.
β Why the Other Options Are Incorrect
A. Change to @InvocableMethod
β₯ @InvocableMethod is used for Flow and Process Builder integration.
β₯ It does not solve the DML-before-callout error.
β₯ Also, @InvocableMethod does not inherently run asynchronously or allow callouts unless combined with future or Queueable context.
B. Remove Database.setSavepoint() and rollback()
β₯ These lines handle transaction rollback and are not related to the DML-callout restriction.
β₯ Removing them won't fix the error β you'd still be making a callout after a DML operation.
π Reference Documentation
Apex Callouts Best Practices
@future Annotation
DML and Callout Order
A developer created a Lightning web component mat allows users to Input a text value that
is used to search for Accounts by calling an Apex method. The Apex method returns a list
of account to apply and is called imperatively from a JavaScript event handler.
Which two changes should the developer make so the Apex method functions correctly?
Choose 2 answers
A. Add @AuraEnabled to line 09.
B. Add @AuraEnabled to line 03.
C. Add @AuraEnabled to lines 11 and 12.
D. Add @AuraEnabled to line 01.
β
Explanation:
π Scenario Summary:
β A Lightning Web Component (LWC) is calling an Apex method imperatively from JavaScript.
β The Apex method returns a list of wrapper objects, which include Account and a custom matchProbability field.
β For the LWC to call this Apex method and process the returned data, specific annotations are required.
π Line-by-Line Breakdown:
β
A. Add @AuraEnabled to line 09.
β The AccountWrapper is returned to LWC.
β For LWC to deserialize and use the properties of this wrapper class (account, matchProbability), each property must be annotated with @AuraEnabled.
β Required for serialization over the wire between Apex and LWC.
β
B. Add @AuraEnabled to line 03.
β The method search() must be @AuraEnabled to be accessible by LWC.
β Since this method is being called imperatively, @AuraEnabled is sufficient (you only need @AuraEnabled(cacheable=true) for wired methods).
β It also needs to be public static, which it already is.
β C. Add @AuraEnabled to lines 11 and 12.
β This is partially correct in idea, but line 09 is the start of the AccountWrapper class, which is where youβd annotate the properties inside the class, not specifically lines 11 and 12.
β Option A already covers this accurately.
β D. Add @AuraEnabled to line 01.
β @AuraEnabled is not valid on classes.
β It is only applied to:
β₯ Methods you want to expose to Lightning components
β₯ Properties inside wrapper classes returned to Lightning
π References:
Lightning Web Components and Apex
@AuraEnabled Annotation
Instead of waiting to send emails to support personnel directly from the finish method of a batch Apex process, Universal Containers wants to notify an external system in the event that an unhandled exception occurs. What is the appropriate publish/subscribe logic to meet this requirement?
A. Publish the error event using the Eventbus. publish () method.
B. No publishing is necessary. Have the external system subscribe to the BatchapexErrorEvent.
C. Publish the error event using the addError method.
D. Publish the error event with a Flow.
β
Explanation:
Salesforce provides a standard platform event called BatchApexErrorEvent that is automatically published by the platform whenever an unhandled exception occurs in a Batch Apex job (in the start, execute, or finish methods).
This event can be consumed by:
β External systems via CometD (Streaming API)
β Internal automation via Platform Event-triggered Flows or Apex Triggers
π Why Option B is Correct
β No custom publishing logic is needed.
β The platform takes care of publishing the BatchApexErrorEvent.
β Your external system simply needs to subscribe to this event using the Streaming API or Change Data Capture/CometD mechanism.
β This approach is reliable, scalable, and aligns with Salesforce event-driven architecture.
β Why the Other Options Are Incorrect
A. Publish the error event using EventBus.publish()
β Incorrect because you donβt need to manually publish the error.
β Salesforce handles it automatically via the BatchApexErrorEvent.
C. Publish the error event using addError
β addError() is used to prevent DML from proceeding and is meant for user feedback or validation, not for error notification or event publishing.
D. Publish the error event with a Flow
β Flows can publish custom platform events, but BatchApexErrorEvent is standard and auto-published.
β Using Flows to publish custom error events adds unnecessary complexity and still wouldn't catch unhandled Batch Apex errors as reliably.
π References:
π§© BatchApexErrorEvent β Salesforce Developer Guide
π§© Event Monitoring for Batch Apex
π§© Streaming API and CometD
Which Salesforce feature allows a developer to see when a user last logged in to Salesforce if real-time notification is not required?
A. Calendar Events
B. Asynchronous Data Capture Events
C. Event Monitoring Log
D. Developer Log
β
Explanation:
Event Monitoring is a Salesforce feature that allows developers and admins to track and analyze user activity, including login history, via log files. These logs include valuable information such as:
β₯ Login Time
β₯ User ID
β₯ IP Address
β₯ Login Status
β₯ Login Type (UI, API, etc.)
This data is not real-time (which aligns with the question requirement) and is available through:
β Event Log Files (ELFs), accessible via:
β₯ REST API
β₯ Event Log File Browser App (in AppExchange)
β₯ Shield Event Monitoring (for more advanced visibility, if licensed)
β Why Other Options Are Incorrect
A. Calendar Events
β Related to user-created appointments and tasks, not login or security tracking.
β Does not provide login data or system activity logs.
B. Asynchronous Data Capture Events
β This option doesn't exist in Salesforce as a specific named feature.
β Might be confused with Change Data Capture, which tracks data changes, not user logins.
D. Developer Log (Debug Log)
β Shows logs for code execution (Apex, triggers, etc.) for specific users.
β Only logs activity when explicitly enabled.
β Does not passively track logins or provide consistent historical login data.
π Reference Documentation:
1. Salesforce Event Monitoring Overview
2. Event Log File Browser (AppExchange Tool)
3. Login History in Salesforce
A company's support process dictates that any time a case is closed with a status of "Could net fix," an Engineering Review custom object record should be created and populated with information from the case, the contact, and any of the products associated with the case. What Is the correct way to automate this using an Apex trigger?
A. An after update trigger on Case that creates the Engineering Review record and inserts it
B. An after upset trigger on Case that creates the Engineering Review record and inserts It .
C. A before update trigger on Case that creates the Engineering Review record and Inserts It
D. A before upset trigger on Case that creates the Engineering Review record and Inserts it
β
Explanation:
This automation needs to occur after a Case is updated, specifically when its Status = 'Could not fix' and the Case is closed. Based on these conditions, letβs break down why an after update trigger is the right choice.
π Why after update is correct:
β‘οΈ Youβre creating a new related record (Engineering_Review__c) based on the values of the Case, Contact, and associated Products.
β‘οΈ Accessing related objects (like Case.Contact or Case.Products) is more reliable in an after trigger, because the parent Case record has already been committed to the database.
β‘οΈ You cannot safely perform DML operations (like insert) on unrelated records inside a before trigger without risk of partial commits or recursion issues.
β Why Other Options Are Incorrect:
B. An after upsert trigger
β There's no such thing as a trigger type named after upsert.
β Triggers respond to insert, update, delete, etc., not upsert directly.
β Upsert is a DML operation, but you'd still write before insert, after update, etc.
C. A before update trigger
β You should not perform DML operations (like creating/inserting new records) in a before trigger for unrelated objects.
β before triggers are intended for modifying the same records being saved β not for creating new ones.
D. A before upsert trigger
β Again, no such trigger exists.
β And performing inserts in a before context is not recommended for this use case.
β
Use Case Best Practice Summary:
β Use an after update trigger when creating related records after the main record (here, Case) has been successfully updated.
Check the status condition inside the trigger:
β Only create Engineering_Review__c when Status == 'Could not fix' and it's a transition from some other status (to avoid duplicates).
β Always bulkify the logic to handle multiple Cases.
π Reference:
β Salesforce Apex Triggers β Developer Guide
β Trigger Context and Best Practices
Which three Visualforce components can be used to initiate Ajax behavior to perform
partial page updates?
(Choose 3 answers)
A. Option A
B. Option B
C. Option C
D. Option D
E. Option E
β
Explanation:
β
B.
β Can initiate an Ajax request by setting action and reRender attributes.
β When used with reRender, it triggers a partial page update for specified components.
β
D.
β Manages the status (like a spinner or loading message) during an Ajax call.
β Works with components like
β Doesn't initiate the Ajax request directly but supports and enhances the Ajax behavior.
β
E.
β Adds Ajax behavior to non-Ajax components (like
β Fires Ajax events like onchange, onclick, etc., and can reRender specific parts of the page.
β A.
β This would normally be a correct answer, but it appears to be a misspelled or invalid option (
β If it were
β C.
β Required as a container for input components and command buttons but does not initiate Ajax behavior.
β It simply enables interaction between components but does not trigger partial page updates by itself.
π References:
β© Visualforce Developer Guide β Ajax Components
β© Understanding
β© Visualforce
A developer needs to add code to a Lightning web component's configuration file so the component only renders for a desktop size form factor when on a record page. What should the developer add to the component's record page target configuration to meet this requirement?
A. Option A
B. Option B
C. Option C
D. Option D
β
Explanation:
The correct choice is Option B.
β€ Salesforce Lightning Web Components allow you to control on which device form factors a component is exposed by using the
β€ either of the other options meets this requirement: the
β€ By leveraging the supported form factors feature, you maintain clean separation of concernsβyour componentβs rendering logic remains focused on business requirements, while the metadata governs where it can be placed.
Reference:
β Salesforce Lightning Web Components Metadata Configuration, Supported Form Factors
Consider the following code snippet:
How should the
A. Create and fire a component event.
B. Create and fire an application event.
C. Create and fire a standard DOM event.
D. Create and dispatch a custom event,
β
Explanation:
The code snippet shows a Lightning Web Component (LWC) using a template for: each> directive to iterate over a orders.data collection, rendering an
In LWC, communication between components can occur in several ways:
β Component Events: These are custom events fired from a child component to its parent component. This is the most common and recommended approach for parent-child communication in LWC.
β Application Events: These are global events that can be handled by any component, but they are less common and generally discouraged in favor of component events or the pub/sub model.
β Standard DOM Events: These are native browser events (e.g., click, change) and are not typically used for custom component communication in LWC.
β Custom Events: In LWC, custom events are created and dispatched using the CustomEvent API, which is the mechanism for firing component events.
Given that the
Correct Answer:
D. Create and dispatch a custom event.
Steps to Implement:
In the
Reference:
Communicate with Events
Lightning Web Components Basics
An org has a requirement that addresses on Contacts and Accounts should be normalized to a company standard by Apex code any time that they are saved. What is the optimal way to implement this?
A. Apex triggers on Contact and Account that call a helper class to normalize the address
B. Apex trigger on Account that calls the Contact trigger to normalize the address
C. Apex triggers on Contact and Account that normalize the address
D. Apex trigger on Contact that calls the Account trigger to normalize the address
β
Explanation:
To meet the requirement of normalizing addresses on both Contact and Account whenever they're saved, Option A is the most modular, maintainable, and scalable approach.
β
Why A is correct:
β Having triggers on both objects ensures that address normalization logic is run independently whenever either object is inserted or updated.
β By delegating the logic to a shared helper class, the code becomes reusable, DRY (Donβt Repeat Yourself), and easier to test.
β This structure keeps the trigger lightweight and avoids logic duplication.
π This follows the Trigger β Handler β Helper design pattern, which is a Salesforce best practice.
β Why B is incorrect:
β An Apex trigger on Account that calls the Contact trigger is not supported or reliable. Triggers donβt call each other explicitly.
β Cross-object triggering in this way would require an update to the Contact, which could lead to recursive triggers and governor limit issues.
β Why C is incorrect:
β Although it works, placing normalization logic directly inside the triggers makes the code hard to maintain, difficult to test, and not reusable.
β This approach violates the Single Responsibility Principle and does not align with enterprise coding standards.
β Why D is incorrect:
β Similar to B, calling one trigger from another objectβs trigger is not a valid or reliable pattern.
β Account and Contact are separate sObjects, and their triggers donβt naturally invoke one another.
β It would require updates that could lead to performance problems, complex debugging, or infinite loops.
π Reference:
β Apex Trigger Best Practices β Salesforce Developer Guide
π§ Key Takeaway:
Use triggers on both objects and delegate logic to a shared Apex helper class to ensure clean, maintainable, and scalable code.
Page 8 out of 21 Pages |
Salesforce-Platform-Developer-II Practice Test Home | Previous |