A developer is tasked with ensuring that email addresses entered into the system for Contacts and for a custom object called survey Response c do not belong to a list of blocked domains.
The list of blocked domains is stored in a custom object for ease of maintenance by users. The survey Response c object is populated via a custom Visualforce page.
What is the optimal way to implement this?
A. Implement the logic in validation rules on the Contact and the Burvey Response_c Objects.
B. Implement the logic in a helper class that is called by an Apex trigger on Contact and from the custom Visualforce page controller.
C. Implement the logic in an Apex trigger on Contact and also implement the logic within the custom Visualforce page controller.
D. Implement the logic in the custom Visualforce page controller and call "that method from an Apex trigger on Contact.
Explanation:
Validation rules (Option A) cannot reference data in other objects, such as the custom object storing the blocked domains, so they are unsuitable for this requirement. Instead, centralizing your validation logic in a helper class allows you to query the custom object for blocked domains and verify that the entered email domain is not on the list. This approach promotes code reuse and ensures consistency:
The helper class can be invoked from an Apex trigger on Contact, ensuring that any email entered via the standard Contact UI is validated.
The Visualforce page controller for the Survey_Response__c object can call the same helper class, maintaining consistent logic and avoiding code duplication.
This design adheres to best practices by separating business logic from presentation, improving maintainability, and ensuring that both data entry points (Contacts and Survey_Response__c) have the same validation behavior.
There is an Apex controller and a Visualforce page in an org that displays records with a custom filter consisting of a combination of picklist values selected by the
user.
The page takes too long to display results for some of the input combinations, while for other input choices it throws the exception, "Maximum view state size limit exceeded”.
What step should the developer take to resolve this issue?
A. Adjust any code that filters by picklist values since they are not indexed,
B. Remove instances of the transient keyword from the Apex controller to avoid the view state error.
C. Use a StandardSetController or SOQL LIMIT in the Apex controller to limit the number of records displayed at a time.
D. Split the layout to filter records in one Visualforce page and display the list of records in a second page using the same Apex controller.
Explanation:
The error "Maximum view state size limit exceeded" occurs when too much data is stored in the Visualforce view state, which includes:
Controller state
Component tree
Field values
Large collections (like record lists)
If a Visualforce page queries and displays too many records at once, the view state becomes too large, leading to this error and performance issues.
Why StandardSetController or SOQL LIMIT is the right solution:
The StandardSetController is built for efficient pagination, and it minimizes the amount of data stored in the view state by loading only a pageful of records at a time.
Using a LIMIT clause in your SOQL reduces the number of returned records and therefore the size of the data bound to the page.
Reference: StandardSetController Docs
A developer is asked to find a way to store sacret data with an ability to specify which profiles and users can access which secrets.
What should be used to store this data?
A. system.Cookie class
B. Custom settings
C. Static resources
D. Custom metadata
Explanation:
When you need to store secret data that must vary by user or profile, Salesforce’s Hierarchy Custom Settings are a common solution. Hierarchy Custom Settings allow you to set default values at the org level and then override them at the profile or user level. This built‑in hierarchy mechanism is ideal when you want to control which users or profiles see which secret values. It also provides ease of maintenance by allowing administrators to update these settings through the Setup interface.
Custom Metadata (Option D) is designed for configuration data that’s typically the same across all users and isn’t subject to record-level (i.e., user or profile–based) access control. The other options (system.Cookie class and static resources) aren’t appropriate for storing secret data with such granular access controls.
A company uses Salesforce to sell products to customers. They also have an external product information management (PIM) system that is the system of record for products.
A developer received these requirements:
* Whenever a product is created or updated in the PIM, a product must be
created or updated as a Product? record in Salesforce and a PricebookEntry
record must be created or updated automatically by Salesforce.
= The PricebookEntry should be created in a Priceboek2 that is specified in a
custom setting.
What should the developer use to satisfy these requirements?
A. Event Monitoring
B. Invocable Action
C. SObject Tree REST
D. Custom Apex REST
Explanation:
In this scenario, the system of record is an external PIM (Product Information Management) system, and Salesforce must:
Accept create/update requests for Product2 records.
Automatically create or update PricebookEntry records.
Use a custom setting to determine which Pricebook2 to use.
Because Salesforce must receive incoming requests from the external system, and the process involves custom business logic (e.g., using a custom setting), the optimal approach is to:
Expose a Custom Apex REST API endpoint using @RestResource
This allows you to:
Define a custom REST interface (e.g., /services/apexrest/products/)
Accept payloads from the external system (e.g., in JSON format)
Perform complex logic like:
Upserting Product2 records
Querying the custom setting for the appropriate Pricebook2
Upserting PricebookEntry records with custom logic
Return success/failure responses
A company has an Apex process that makes multiple extensive database operations and web service callouts. The database processes and web services can take a long time to run and must be run sequentially.
How should the developer write this Apex code without running into governor limits and system limitations?
A. Use Queueable Apex to chain the jobs to run sequentially.
B. Use Apex Scheduler to schedule each process.
C. Use multiple 3zutuze methods for each process and callout.
D. Use Limits class to stop entire process once governor limits are reached.
Explanation:
The best approach to handle long-running Apex processes with sequential database operations and web service callouts is to use Queueable Apex. This method allows you to break down complex tasks into smaller, manageable jobs that execute one after another, ensuring each step runs in its own transaction with fresh governor limits. Unlike @future methods, Queueable Apex supports both DML operations and callouts, making it ideal for workflows that require interacting with databases and external APIs. Additionally, Queueable jobs can chain themselves, meaning each job can enqueue the next step upon completion, maintaining the required sequential order. This design prevents governor limit issues like CPU timeouts or excessive DML operations, as each job operates independently. Alternatives like the Apex Scheduler lack the ability to chain jobs tightly, while @future methods cannot guarantee order or handle callouts and DML in the same context. The Limits class merely monitors limits reactively but doesn’t solve the root problem. By leveraging Queueable Apex, developers ensure scalability, error isolation, and efficient resource usage, making it the only robust solution for this scenario.
Universal Containers stores user preferences in a hierarchy custom setting,
user Prefs_c, with a checkbox field, show _help co. Company-level defaults are
stored at the organizational level, but may be overridden at the user level. If a user
has not overridden preferences, then the defaults should be used.
How should the show_Help_ c preference be retrieved for the current user?
A. Boolean show = User_Prefa_ c.getValuea().Show_Help_ co;
B. Boolean show = User Prefs c.getValues(UserInfo.getUserid{)).Show_Help c;
C. Boolean show = User_Prefs_c.getlnstance(].Show Help c;
D. Boolean show = User Prefs_c.show Melp_c;
Explanation:
To retrieve the Show_Help__c preference for the current user while respecting hierarchy custom setting overrides, you must use the getInstance() method. Here’s why:
Hierarchy Behavior:
User_Prefs__c.getInstance() automatically checks for:
User-level overrides (if set).
Falls back to org-wide defaults if no user override exists.
This matches the requirement to "use defaults if the user hasn’t overridden preferences."
Correct Syntax:
The proper way to access the field is:
User_Prefs__c.getInstance().Show_Help__c;
getInstance() returns the most specific setting for the current user.
Why Other Options Fail:
A: getValuea() and Show_Help_co are invalid (typos).
B: getValues(UserId) forces a lookup for a specific user, ignoring the hierarchy’s fallback logic.
D: Direct field access (User_Prefs__c.Show_Help__c) is invalid—you must call getInstance() first.
A developer has a test class that creates test data before making a mock callout but now receives a 'You have uncommitted work pending. Please commit or rollback before calling out’ error.
Which step should be taken to resolve the error?
A. Ensure both the Insertion and mock callout occur after the I==L. stoptest_().
B. Ensure the records are Inserted before the Tezt.startTest() statement and the mock callout occurs within a method annotated with @testSetup.
C. Ensure both the insertion and mock callout occur after the Test.startTest().
D. Ensure the records are inserted before the Test.startTess() statement and the mock callout occurs after the Test. Startest().
Explanation:
The error:
“You have uncommitted work pending. Please commit or rollback before calling out.”
...occurs when DML (insert/update/delete) happens in the same transaction before a callout. Salesforce does not allow callouts and DML to be mixed unless they are properly sequenced.
Correct Practice:
Do all DML (record creation) before Test.startTest().
Perform mock callouts (e.g., via HttpCalloutMock) after Test.startTest().
Test.startTest() marks the boundary where governor limits are reset and is also the proper place to begin callouts in test methods.
Example:
@isTest
static void testCalloutLogic() {
// Create test data BEFORE callout
Account a = new Account(Name = 'Test Account');
insert a;
// Start test context and limits
Test.startTest();
// Register mock and invoke method that performs callout
Test.setMock(HttpCalloutMock.class, new MyMockCallout());
MyCalloutClass.performCallout(a.Id);
Test.stopTest();
}
A developer is trying to decide between creating a Visualforce component or a Lightning component for a custom screen.
Which functionality consideration impacts the final decision?
A. Does the screen need to be accessible from the Lightning Experience UI?
B. Does the screen need to be rendered as a PDF without using a thirdparty application?
C. Will the screen make use of a JavaScript framework?
D. Will the screen be accessed via a mobile app?
Explanation:
One of the most critical functional differences between Visualforce components and Lightning components (Aura or LWC) is their support for server-side rendering and PDF generation.
Why B is correct:
Visualforce pages can be rendered as PDFs natively using the
Lightning components (LWC/Aura) do not support rendering as PDF directly — you'd need to use a third-party service or workaround.
So if your screen needs server-side PDF generation without third-party tools, Visualforce is required.
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 built-in BatchApexErrorEvent platform event that automatically fires when an unhandled exception occurs in a batch Apex job. This event contains valuable information such as the exception type, message, stack trace, and affected records. Since this event is published automatically, no additional publishing logic is required. Instead, the external system can subscribe to the BatchApexErrorEvent and listen for error notifications in real time.
This approach ensures that errors are captured efficiently without requiring manual intervention or additional Apex logic. The external system can process the event and take appropriate action, such as logging the error or triggering an automated response.
Universal Containers ne=ds to integrate with several external systems. The process Is Initiated when a record Is created in Salesforce, The remote systems do not require Salesforce to wait for a response before continuing. What is the recommended best solution to accomplish this?
A. PushTopic event
B. Qutbound message
C. Trigger with HTTP callout
D. Platform event
Explanation:
Since the external systems do not require Salesforce to wait for a response before continuing, the best approach is to use Platform Events. Platform Events provide an efficient publish-subscribe model, allowing Salesforce to notify external systems asynchronously when a record is created. This ensures that the integration process does not block Salesforce transactions and avoids governor limits associated with synchronous callouts.
Using Platform Events:
Decouples Salesforce from external systems, allowing them to process events independently.
Ensures scalability, as multiple external systems can subscribe to the same event.
Avoids callout limitations, since the event is published without requiring an immediate response.
Other options:
PushTopic event is used for streaming real-time updates but is not ideal for triggering external integrations.
Outbound messages are limited to workflow rules and do not provide the flexibility of Platform Events.
Trigger with HTTP callout would require synchronous execution, which is not recommended due to governor limits.
A corporation has many different Salesforce orgs, with some different objects and some common objects, and wants to build a single Java application that can create, retrieve, and update common object records in all of the different orgs.
Which method of integration should the application use?
A. SOAP API with the Partner WSDL
B. Apex REST Web Service
C. SOAP API with the Enterprise WSDL
D. Metadata APT
Explanation:
The corporation wants to build a single Java application that can create, retrieve, and update common object records across many different Salesforce orgs, some of which have different schemas.
Why Partner WSDL is the best choice:
The Partner WSDL is loosely typed and schema-flexible.
It allows the Java application to work with sObject types dynamically without needing to regenerate the WSDL for each Salesforce org.
Ideal for multi-org integration, where object definitions may differ.
Enables the app to read metadata at runtime and perform CRUD operations on standard/custom objects.
A developer writes a Lightning web component that displays a dropdown list of all custom objects in the org from which a user will select. An Apex method prepares and returns data to the component.
What should the developer do to determine which objects to include in the response?
A. Check the isCustom() value on the sObject describe result,
B. Import the list of all custom objects from @salesforce/schema.
C. Check the getobiectType [) value for ‘Custom’ or "Standard’ on the sObject describe result.
D. Use the getcustomobjects() method from the Schema class.
Explanation:
To display a dropdown list of all custom objects in a Lightning Web Component, the Apex method must:
Use the Schema class to get all SObject types.
Check each object’s describe result to determine if it is a custom object.
Return the list of custom objects to the LWC.
Why isCustom() is correct:
The isCustom() method of the DescribeSObjectResult class returns true if the object is custom.
You can loop through all SObjects using Schema.getGlobalDescribe() and filter for custom objects using describeResult.isCustom().
Page 4 out of 17 Pages |
Previous |