Salesforce Certified Platform Developer II Free Sample Questions

Description

Covers base system objects, multi-language data modeling and external IDs, order of execution and error handling, Visualforce controllers, query performance, web service integration, and testing.

20 free sample questions251 in the full practice test Other version: Plat-Dev-301(129)

Try simulator

Platform Developer II Sample Questions

  1. Question 1

    Intermediate

    Logic and Process Automation · Error Handling and Transactional Integrity

    A financial services company uses a custom Apex REST service to receive transaction data from a third-party system. The service must process batches of up to 200 transactions, create corresponding custom Transaction__c records, and update the related Account. If any transaction in the batch is invalid, the entire operation must be rolled back, and a specific error message must be returned. Which Apex feature is most appropriate for maintaining transactional integrity in this scenario?

    Answer and explanation

    Correct answer: C

    Using Database.Savepoint and Database.rollback() provides explicit control over the transaction. By setting a savepoint before attempting the DML operations, the developer can catch any exception, roll back all changes to the state of the database before the savepoint was set, and then return a controlled error message. A simple try-catch with a thrown exception also rolls back the transaction, but using a savepoint is the canonical and most explicit way to manage partial transaction rollbacks or full rollbacks while maintaining control over the execution flow to return a specific response.

  2. Question 2

    Intermediate

    User Interface · Lightning Components

    A developer is building a Lightning Web Component to display a list of related Case records on an Account page. The component must be reusable and configurable by an administrator, allowing them to specify the Status and Priority to filter the cases shown. How should the developer implement this configurability for the Lightning App Builder?

    Answer and explanation

    Correct answer: C

    To make LWC properties configurable in the Lightning App Builder, they must be declared as public properties using the @api decorator in the component's JavaScript file. Additionally, these properties must be exposed in the component's configuration file (.js-meta.xml) within the section. This allows administrators to set values for these properties directly in the App Builder's UI.

  3. Question 3

    Advanced

    Logic and Process Automation · Asynchronous Execution

    Universal Containers needs to synchronize large volumes of Product__c records (potentially over 1 million) nightly from an external Product Information Management (PIM) system. The process involves complex transformations and enrichment logic that cannot be handled by middleware. A developer has decided to implement this using Batch Apex. To optimize performance and avoid governor limit issues, what is the best approach for the start method to query the records to be processed?

    Answer and explanation

    Correct answer: B

    For processing large data sets (over 50,000 records), Database.QueryLocator is the optimal choice for the start method of a Batch Apex class. It bypasses the heap size limit for the total number of records retrieved by the query because it fetches records in chunks. In contrast, returning an Iterable or a List loads all records into the heap at once, which would cause a heap limit exception with over 1 million records.

  4. Question 4

    IntermediateMultiple answers

    Testing · Test Data and Mocking

    A developer needs to write a unit test for a method that makes an HTTP callout to an external weather service. The test must verify the logic that parses the JSON response and updates a Forecast__c record. Which two approaches are necessary to ensure the test runs successfully without making a real callout and properly isolates the test data? (Select TWO)

    Answer and explanation

    Correct answers: A, C

  5. Question 5

    Intermediate

    Performance · User Interface Performance

    A Visualforce page uses a custom controller to display a data table of Opportunity records. The controller uses a large, complex SOQL query to gather the data. Users report that the page sometimes throws a 'Maximum view state size limit exceeded' error, especially when filtering results that return many rows. Which modification is the most effective way to mitigate this specific error?

    Answer and explanation

    Correct answer: B

    The view state error is caused by large amounts of data being stored in the controller's properties between server requests. The transient keyword prevents a variable from being saved as part of the view state. While this means the data will need to be re-fetched on each postback, it directly solves the 'Maximum view state size' error by removing the large data list from the view state.

  6. Question 6

    Advanced

    Data Modeling and Management · Custom Metadata and Custom Settings

    Quantum Logistics has a complex, multi-lingual Salesforce org. They need to store configuration data for a custom shipping calculator, including shipping rates, service levels, and country-specific surcharges. This configuration data must be deployable between sandboxes and production, and it needs to be easily queryable within Apex. The data structure is relational, with 'Service Levels' being a parent to 'Country Surcharges'. What is the most appropriate solution for storing this configuration data?

    Answer and explanation

    Correct answer: D

    Custom Metadata Types are the best fit for this scenario. They are deployable, meaning the configuration data can be moved between environments as metadata. They can be queried using SOQL, and they support relationships, allowing the developer to model the parent-child structure between 'Service Levels' and 'Country Surcharges'. Custom Objects are data, not metadata, and are harder to deploy. Custom Settings are not as well-suited for complex relational structures and are less easily deployed.

  7. Question 7

    Advanced

    Performance · Query Performance

    A developer at a large enterprise is tasked with creating a nightly batch job that deactivates Contact records that have not been logged into a community for over 180 days. The org contains over 10 million Contact records. The initial SOQL query SELECT Id FROM Contact WHERE LastLoginDate < LAST_N_DAYS:180 is timing out. What is the most effective way to resolve this query performance issue?

    Answer and explanation

    Correct answer: B

    The query is timing out because it is non-selective. It has to perform a full table scan on 10 million records to find contacts where LastLoginDate is older than 180 days. Standard date fields like LastLoginDate are not indexed by default. The most effective solution is to work with Salesforce Support to create a custom index on this field. This will make the query highly selective and allow it to execute efficiently without timing out.

  8. Question 8

    Beginner

    Data Modeling and Management · External IDs

    True or False: When using the Database.upsert method with an External ID field, if multiple records in the database match the provided External ID, the operation will throw a DML exception.

    Answer and explanation

    Correct answer: A

    This statement is true. The External ID field must uniquely identify a single record for the upsert operation to succeed. If the value of the External ID field is not unique and matches multiple existing records, the operation will fail and a DmlException will be thrown, indicating that multiple records were found for the upsert.

  9. Question 9

    Beginner

    Logic and Process Automation · Declarative and Programmatic Integration

    A developer needs to expose an Apex method that can be called from a Process Builder or Flow. The method should accept a list of Opportunity IDs and perform a complex calculation that is not possible with declarative tools. Which annotation must be used for the Apex method?

    Answer and explanation

    Correct answer: C

    The @InvocableMethod annotation is specifically designed to expose an Apex method as a callable action in declarative tools like Process Builder, Flow, and the REST API. The method must be static and can have only one parameter, which must be a list of a primitive data type or a custom Apex class.

  10. Question 10

    Advanced

    Logic and Process Automation · Asynchronous Execution

    A business process requires that when an Opportunity is updated, a callout is made to an external system to reserve inventory. This callout must not delay the saving of the Opportunity record. If the callout fails, it should be automatically retried up to three times. Which asynchronous Apex pattern best meets all these requirements?

    Answer and explanation

    Correct answer: B

    Queueable Apex is the best fit. It runs asynchronously, so it won't delay the Opportunity save. Crucially, a Queueable job can enqueue another job from within its execute method, which allows for complex patterns like implementing a retry mechanism. The job can maintain a retryCount state variable and, upon failure, re-enqueue itself if the count is below the threshold. @future methods cannot call other @future methods, and Batch Apex is overkill for a single callout.

Register free for 10 more questions

Or unlock all 251 Platform Developer II questions with explanations, timed mode and flashcards.