Salesforce-Platform-Developer-II Practice Test
Updated On 1-Jan-2026
202 Questions
Refer to the Lightning component below:
The Lightning Component allows users to click a button to save their changes and then redirects them to a different page.
Currently when the user hits the Save button, the records are getting saved, but they are
not redirected.
Which three techniques can a developer use to debug the JavaScript?
(Choose 3 answers)
A. Use console.log () messages in the JavaScript.
B. Use the browser's dev tools to debug the JavaScript.
C. Enable Debug Mode for Lightning components for the user.
D. Use Developer Console to view checkpoints.
E. Use Developer Console to view the debug log.
B. Use the browser's dev tools to debug the JavaScript.
C. Enable Debug Mode for Lightning components for the user.
Explanation:
To debug the issue where a Lightning Component (Aura or LWC) saves records successfully but fails to redirect users to a different page after clicking the Save button, the developer needs to identify why the redirection logic in the JavaScript is not executing or failing. Since the code snippet is not provided, I’ll assume a typical scenario: the component has a button with an onclick handler that calls a server-side action (e.g., Apex) to save records and then attempts a navigation (e.g., using e.getSource().get("e.force:navigateToURL") in Aura or this[NavigationMixin.Navigate]() in LWC). The debugging techniques should help trace the JavaScript execution flow, identify errors, and verify the navigation step. Let’s evaluate the options based on Salesforce debugging practices.
Key Considerations:
✔ The issue is in the JavaScript, so debugging techniques should focus on client-side execution.
✔ Common causes include unhandled exceptions, incorrect navigation syntax, or asynchronous timing issues (e.g., navigation before the save completes).
✔ Salesforce provides multiple tools for JavaScript debugging in Lightning components.
Evaluation of Options:
A. Use console.log() messages in the JavaScript.
Adding console.log() statements at key points (e.g., before and after the save call, after navigation) allows the developer to trace the execution flow, verify variable values (e.g., URL), and detect where the code stops. This is a standard, lightweight debugging technique for JavaScript in Lightning components, making it an effective choice.
B. Use the browser's dev tools to debug the JavaScript.
The browser’s developer tools (e.g., Chrome DevTools) provide a debugger to set breakpoints, step through JavaScript code, inspect variables, and view console output or network requests. This is ideal for diagnosing runtime errors or navigation failures in Lightning components, as it offers detailed control over client-side execution, making it a strong option.
C. Enable Debug Mode for Lightning components for the user.
Enabling Debug Mode for Lightning components (via User settings or URL parameter ?debug=1) unminifies the JavaScript, making it readable in browser dev tools and providing more detailed error messages. This helps identify syntax errors or framework issues that might prevent redirection, making it a useful technique for debugging.
D. Use Developer Console to view checkpoints.
Checkpoints in the Developer Console allow pausing execution and inspecting variable states in Apex code, but they are not applicable to JavaScript in Lightning components. This technique is irrelevant for client-side debugging, making this option incorrect.
E. Use Developer Console to view the debug log.
Debug logs in the Developer Console capture server-side Apex execution (e.g., DML, exceptions), but they do not include client-side JavaScript details like navigation failures. While useful for verifying the save operation, they won’t help debug the JavaScript redirection issue, making this option incorrect.
Correct Answers: A. Use console.log() messages in the JavaScript, B. Use the browser's dev tools to debug the JavaScript, and C. Enable Debug Mode for Lightning components for the user.
Reason:
✔ A: console.log() provides immediate feedback on the JavaScript flow, helping identify if the navigation code is reached or if an error occurs (e.g., console.log('Navigating to:', url);).
✔ B: Browser dev tools allow setting breakpoints (e.g., in the handleSave method) to step through the code, inspect the navigation call (e.g., navigateToURL), and catch exceptions, offering deep debugging.
✔ C: Debug Mode enhances visibility into JavaScript errors by unminifying the code, making it easier to pinpoint issues like syntax errors or framework misconfigurations affecting redirection.
Inferred Debugging Approach:
Assumed Code (Aura Example):
handleSave: function(component, event, helper) {
var action = component.get("c.saveRecord");
action.setCallback(this, function(response) {
if (response.getState() === "SUCCESS") {
var url = '/lightning/n/MyPage';
var navEvt = $A.get("e.force:navigateToURL");
navEvt.setParams({ url: url });
navEvt.fire(); // Check if this fires
}
});
$A.enqueueAction(action);
}
➟ Add console.log('Save success'); before navEvt.fire() and use dev tools to confirm execution.
Assumed Code (LWC Example):
import { LightningElement, api } from 'lwc';
import { NavigationMixin } from 'lightning/navigation';
export default class MyComponent extends NavigationMixin(LightningElement) {
handleSave() {
saveRecord() // Apex call
.then(() => {
this[NavigationMixin.Navigate]({
type: 'standard__navItemPage',
attributes: { pageName: 'myPage' }
});
});
}
}
➟ Add console.log('Navigating'); in the .then block and use dev tools to step through.
Reference: Salesforce Lightning Component Library - Debugging Lightning Components, Salesforce Help - Enable Debug Mode.
Additional Notes:
Start with console.log() to isolate the issue (e.g., save succeeds but navigation fails). Use dev tools to set breakpoints and inspect the navigation event or promise. Enable Debug Mode via the URL (/one/one.app?debug=1) or user settings to see detailed errors. Check for unhandled exceptions or incorrect navigation parameters (e.g., invalid URL). Test in a sandbox to avoid production impact.
Refer to the following code snippets:
A developer is experiencing issues with a Lightning web component. The component must
surface information about Opportunities owned by the currently logged-in user.
When the component is rendered, the following message is displayed: "Error retrieving
data”.
Which modification should be implemented to the Apex class to overcome the issue?
A. Use the Cacheable=true attribute in the Apex method,
B. Ensure the OWD for the Opportunity object is Public.
C. Edit the code to use the w. cut sharing keyword in the Apex class.
D. Use the Continuation=true attribute in the Apex method.
Explanation:
To address the issue where a Lightning Web Component (LWC) displays "Error retrieving data" when attempting to surface information about Opportunities owned by the currently logged-in user, we need to identify the likely cause based on the provided code snippets (not fully visible) and the options. Since the code snippets are not fully included, I’ll infer a common scenario: the LWC uses an @wire adapter to call an Apex method that queries Opportunities, but the call fails due to security, caching, or execution issues. Let’s evaluate the options based on LWC and Apex best practices.
Assumed Scenario:
➡️ The LWC uses @wire to invoke an Apex method (e.g., getMyOpportunities) annotated with @AuraEnabled.
➡️ The Apex method queries Opportunities (e.g., SELECT Id, Name FROM Opportunity WHERE OwnerId = :UserInfo.getUserId()).
➡️ The error suggests a failure in data retrieval, possibly due to security restrictions (e.g., sharing rules), lack of caching for @wire, or an incorrect execution context.
Key Considerations:
✔ LWC @wire requires @AuraEnabled(cacheable=true) on Apex methods to cache results and avoid repeated server calls, improving performance and preventing errors if the method isn’t cacheable.
✔ The "with sharing" keyword enforces the user’s sharing rules, which is critical if the OWD (Organization-Wide Defaults) for Opportunity is private, restricting access to owned records.
✔ The error message is generic, so the fix must address a common LWC-Apex integration issue.
Evaluation of Options:
A. Use the cacheable=true attribute in the Apex method.
The @AuraEnabled(cacheable=true) annotation is required for Apex methods called via LWC @wire to cache the results on the client side, reducing server load and ensuring the method can be invoked without security or governor limit issues during rendering. Without cacheable=true, the @wire service may fail with an error if the method performs DML or lacks proper sharing context, especially for real-time data like owned Opportunities. Adding this attribute (if missing) is a standard fix for such errors, making this a likely solution.
B. Ensure the OWD for the Opportunity object is Public.
Changing the OWD to Public Read/Write or Public Read Only would grant all users access to all Opportunity records, bypassing sharing rules. However, the requirement is to surface only Opportunities owned by the logged-in user, which suggests the current OWD is private or controlled by sharing rules. Adjusting OWD is a configuration change, not a code modification, and would over-permit access, making this incorrect for the specific need.
C. Edit the code to use the with sharing keyword in the Apex class.
The with sharing keyword enforces the user’s sharing rules in the Apex class, ensuring the query respects the logged-in user’s access (e.g., only seeing owned Opportunities if OWD is private). If the class is currently without sharing or has no sharing declaration, the query might return no records or fail due to insufficient permissions, causing the error. Adding with sharing (e.g., public with sharing class MyClass) is a code modification that aligns with the requirement and could resolve the issue, making this a plausible solution.
D. Use the Continuation=true attribute in the Apex method.
The @AuraEnabled(continuation=true) annotation is used for long-running callouts (e.g., HTTP requests exceeding 10 seconds), not for standard SOQL queries like those for Opportunities. This attribute is irrelevant to the described scenario and would not address the "Error retrieving data" issue, making this option incorrect.
Correct Answers: A. Use the cacheable=true attribute in the Apex method and C. Edit the code to use the with sharing keyword in the Apex class.
Reason:
➜ A: Adding cacheable=true to the @AuraEnabled method ensures the LWC @wire service can cache the query results, preventing errors during rendering. This is critical for LWC components, as uncacheable methods (default behavior without cacheable=true) cannot be wired directly and may fail with generic errors.
➜ C: Adding with sharing to the Apex class ensures the query respects the user’s sharing rules, limiting results to Opportunities the logged-in user owns (given the private OWD). This prevents unauthorized access or query failures due to security restrictions.
➥ Inferred Fixed Code:
public with sharing class OpportunityController {
@AuraEnabled(cacheable=true)
public static List
return [SELECT Id, Name FROM Opportunity WHERE OwnerId = :UserInfo.getUserId()];
}
}
➥ LWC JS (assumed):
import { LightningElement, wire } from 'lwc';
import getMyOpportunities from '@salesforce/apex/OpportunityController.getMyOpportunities';
export default class MyComponent extends LightningElement {
@wire(getMyOpportunities) opportunities;
}
➜ The cacheable=true allows the @wire to work, and with sharing ensures only owned Opportunities are returned.
Reference: Salesforce LWC Developer Guide - Call Apex Using @wire, Salesforce Apex Developer Guide - with sharing Keyword.
Additional Notes:
Test the component after adding both changes in a sandbox. If the OWD is already private and sharing rules are correct, with sharing should suffice, but cacheable=true is mandatory for @wire. If DML is needed later, remove cacheable=true and use an imperative call. The error might also stem from missing fields in the query—ensure all required fields are included.
The Account object has a field, Audit_Code_c, that is used to specify what type of auditing
the Account needs and a Lookup to User, zudizar_c, that is the assigned auditor. When an
Account is initially created, the user specifies the Audit_Code c. Each User in the org has a
unique text field, Audit_Code _e, that is used to automatically assign the correct user to the Account’s Auditor_c field.
What should be changed to most optimize the code’s efficiency?
(Choose 2 answers)
A. Add an initial SOQL query to get all distinct audit codes.
B. Build a Map
C. Build a Map
D. Add a WHERE clause to the SOQL query to filter on audit codes.
D. Add a WHERE clause to the SOQL query to filter on audit codes.
Explanation:
an Apex trigger or process on the Account object that, upon creation, sets the Auditor__c lookup field based on the Audit_Code__c value matching the Audit_Code__c field on a User record. The goal is to optimize efficiency, likely by reducing SOQL queries, minimizing loops, or improving data structure usage, given the involvement of over 10,000 records (as hinted by prior context). The options suggest improvements to SOQL queries and data mapping. Let’s evaluate the options based on best practices for handling large datasets in Apex.
Assumed Scenario:
➡️ A trigger on Account (after insert) queries User records to find a match between Account.Audit_Code__c and User.Audit_Code__c, then updates Account.Auditor__c.
➡️ Without optimization, this might involve multiple SOQL queries (e.g., one per Account) or inefficient loops, hitting governor limits (e.g., 100 SOQL queries, 10,000 DML rows).
➡️ The solution should minimize queries and use efficient data structures (e.g., Maps).
Key Considerations:
✔ Salesforce governor limits: 100 SOQL queries, 10,000 DML rows per transaction.
✔ For 10,000+ Account records, bulkification is critical to avoid query limits.
✔ A Map can store relationships (e.g., Audit_Code__c to User) to reduce query overhead.
Evaluation of Options:
A. Add an initial SOQL query to get all distinct audit codes.
This suggests querying User records to collect unique Audit_Code__c values before processing Account records. However, this alone doesn’t optimize the assignment logic unless followed by a query to map these codes to User records. It reduces redundant queries if audit codes are pre-filtered, but without a subsequent Map or filter, it’s incomplete. This is a partial step but not sufficient on its own.
B. Build a Map
This likely intends Map
C. Build a Map
This creates a Map
D. Add a WHERE clause to the SOQL query to filter on audit codes.
Adding a WHERE clause (e.g., WHERE Audit_Code__c IN :distinctAuditCodes) to the User SOQL query filters records to only those with relevant Audit_Code__c values, reducing the query’s scope. This complements option A or B, minimizing processed records and improving performance, especially with many User records. This is a valuable optimization when paired with a Map.
✅ Correct Answers: B. Build a Map
Reason:
➤ B: Building a Map
➤ D: Adding a WHERE clause (e.g., WHERE Audit_Code__c IN :auditCodeSet) to the User query, where auditCodeSet is derived from Trigger.new Audit_Code__c values, reduces the query size, enhancing efficiency for large orgs with many User records.
Exhibit.
Given the code above, which two changes need to be made in the Apex Controller for the
code to work? (Choose 2 answers)
A. Annotate the entire class as @AuraEnabled instead of just the single method.
B. Change the argument in the Apex Controller line 05 from subject to string.
C. Change the method signature to be global static, not public to String.
D. Remove line 06 from the Apex Controller and instead use firstName in the return on line 07.
D. Remove line 06 from the Apex Controller and instead use firstName in the return on line 07.
Explanation:
The LWC calls serverEcho with a String parameter (firstName: 'world'), but the Apex method expects an sObject parameter (sobject firstName). This mismatch prevents the method from working, likely throwing a System.TypeException or causing the .catch block to execute.
Evaluation of Options
A. Annotate the entire class as @AuraEnabled instead of just the single method.
The @AuraEnabled annotation is correctly applied to the serverEcho method. Annotating the entire class is invalid syntax and unnecessary, as only methods need @AuraEnabled for Lightning access. This option is incorrect.
B. Change the argument in the Apex Controller line 05 from subject to string.
The question references line 05, which in the Apex Controller is public static String serverEcho(sobject firstName). The option mentions changing subject to string, but the parameter is firstName, not subject (possibly a typo in the option or question). The intent is to change the parameter type from sobject to String to match the LWC’s firstName: this.firstName (a String). This fixes the type mismatch, making this a necessary change.
C. Change the method signature to be global static, not public to String.
The current signature is public static String serverEcho(...), and “public to String” seems to be a typo for “public static String”. Changing to global static is unnecessary for LWC/Aura integration (which works with public) and adds complexity. This option is incorrect.
D. Remove line 06 from the Apex Controller and instead use firstName in the return on line 07.
Line 06 is String firstNameStr = (String) firstName.get('firstName');, which attempts to cast an sObject to a String and access a field. Since firstName is not an sObject (due to the type mismatch), this fails. Removing line 06 and changing line 07 (return ('Hello from the server, ' + firstNameStr)) to return 'Hello from the server, ' + firstName (using the parameter directly) resolves the issue, assuming the parameter is corrected to String firstName. This is a necessary change to simplify and fix the logic.
Correct Answers:
✔ B. Change the argument in the Apex Controller line 05 from subject to string
✔ D. Remove line 06 from the Apex Controller and instead use firstName in the return on line 07.
🧩 Reason:
✅ B: Changing the parameter from sobject firstName to String firstName on line 05 aligns the Apex method with the LWC’s call, which passes a String. This resolves the type mismatch.
✅ D: Removing line 06 (the failed sObject cast) and updating line 07 to return 'Hello from the server, ' + firstName uses the String parameter directly, eliminating the null pointer or casting error.
Part of a custom Lightning component displays the total number of Opportunities in the org, which are in the millions. The Lightning component uses an Apex method to get the data it needs. What is the optimal way for a developer to get the total number of Opportunities for the Lightning component?
A. SOQL for loop that counts the number of Opportunities records
B. Apex batch job that counts the number of Opportunity records
C. SUM () SOQL aggregate query on the Opportunity object
D. COUNT () SOQL aggregate query on the Opportunity object
Explanation:
When working with large datasets in Salesforce, especially in the millions of records, it's critical to retrieve data efficiently and avoid hitting governor limits or causing performance issues. For counting records, SOQL aggregate functions offer the most optimal and scalable solution.
✅ Why D is Correct (COUNT() SOQL aggregate query):
✔ The COUNT() aggregate function is specifically designed to return the number of records that match a query.
✔ Salesforce optimizes this internally, so it does not load all records into memory.
✔ Efficient and governor-limit-friendly, especially when dealing with millions of records.
✔ Returns a single integer value, perfect for UI components needing simple metrics.
🔧 Example:
@AuraEnabled(cacheable=true)
public static Integer getOpportunityCount() {
return [SELECT COUNT() FROM Opportunity];
}
❌ Why Other Options Are Incorrect:
A. SOQL for loop that counts the number of Opportunity records
➞ This approach loads records in chunks of 200, then iterates to count them.
➞ Inefficient and risky with millions of records due to:
➥ Heap size limits
➥ Query row limits
➥ CPU time consumption
➞ Overkill for just counting records.
B. Apex batch job that counts the number of Opportunity records
➞ Batch jobs are designed for complex processing of large datasets asynchronously.
➞ Using a batch job only to count records is excessive and slow.
➞ Overhead of scheduling/running a batch is not justified for a simple count.
C. SUM() SOQL aggregate query
➞ SUM() is used to add values in a numeric field (e.g., SUM(Amount)).
➞ It’s irrelevant for counting records.
➞ You’d use SUM() to get total revenue, not record counts.
📚 Reference:
🔗 COUNT() SOQL Function – Salesforce Developer Guide
🔗 Apex Best Practices – Salesforce
| Salesforce-Platform-Developer-II Exam Questions - Home | Previous |
| Page 6 out of 41 Pages |