Universal Containers has an Apex trigger on Account that creates an Account Plan record when an Account is marked as a Customer.
Recently a record-triggered flow was added so that whenever an Account is marked as a Customer, a "Customer Since’ date field is updated with today's date. Since the addition of the flow, two Account Plan records are created whenever the Account is marked as a Customer.
What might cause this to happen?
A. The Apex trigger does not use a static variable to ensure it only fires once.
B. The flow is configured to use an "Update Records’ element.
C. The Apex trigger is not bulk safe and calls insert inside of a for loop.
D. The flow is configured to evaluate when a record is created and every time it is edited.
Explanation:
This is a classic case of unintended recursion between a trigger and a flow. Let’s walk through the likely sequence:
An Account is updated and marked as a Customer.
The Apex trigger fires and creates an Account Plan.
The record-triggered flow also fires (because the Account was edited), and it updates the "Customer Since" field.
That update causes the Account to be edited again.
Since the flow is configured to run on create and every update, it fires again.
The trigger fires again too—resulting in a second Account Plan record.
This loop continues unless one or both automation tools are designed to prevent re-entry.
A developer is building a Lightning web component that searches
for Contacts. The component must communicate the search
results to other unrelated Lightning web components, that are in
different DOM trees, when the search completes.
What should the developer do to implement the communication?
A. Fire an application event.
B. Publish an event on an event channel.
C. Fire a custom component event.
D. Publish a message on a message channel.
Explanation:
When Lightning Web Components (LWCs) that are unrelated and in different DOM trees need to communicate, the recommended and standard approach is to use the Lightning Message Service (LMS).
LMS allows components to publish and subscribe to messages on a message channel, even if they are:
Not in the same component hierarchy.
In different DOM trees or application containers (like utility bars, pop-ups, etc.).
On the same Lightning page (or even in Experience Cloud sites, Visualforce, or Aura contexts).
In your scenario:
A search component finishes executing.
It needs to broadcast the search results.
Other components (e.g., a contact detail or contact list component) can subscribe to the message channel and react to the results.
This is exactly what Lightning Message Service is designed for.
Universal Containers (LIC) wants to develop a customer community to help their customers log issues with their containers. The community needs to function for their German- and Spanish-speaking customers also. UC heard that it's easy to create an international community using Salesforce, and hired a developer to build out the site.
What should the developer use to ensure the site is multilingual?
A. Use custom labels to ensure custom messages are translated properly.
B. Use custom settings to ensure custom messages are translated properly.
C. Use custom objects to translate custom picklist values.
D. Use custom metadata to translate custom picklist values.
Explanation:
Why Option A (Custom Labels) is Correct?
Built for Multilingual Support:
Custom Labels are Salesforce’s native solution for translating UI text (e.g., error messages, buttons, labels).
Supports multiple languages (German, Spanish, etc.) with zero code changes.
How It Works:
Create a Custom Label:
Setup → Custom Labels → Define a label (e.g., Issue_Submit_Button).
Add Translations:
Upload translations for each language (German: Problem einreichen, Spanish: Enviar problema).
Reference in Code/UI:
Apex: System.Label.Issue_Submit_Button
Lightning/LWC: {!$Label.c.Issue_Submit_Button}
Visualforce: {!$Label.Issue_Submit_Button}
Automatic Language Detection:
Salesforce serves the correct translation based on the user’s language/locale settings.
Universal Containers (UC) has enabled the translation workbench and has translated picklist values. UC has a custom multi-select picklist field, Product__c, on the Account object that allows sales reps to specify which of UC’s products an Account already has. A developer is tasked with writing an Apex method that retrieves Account records, including the Product_c field.
What should the developer do to ensure the value of Products__c is in the current user's language?
A. Use tolabel ducts__c) in the fields list of the SOQL query.
B. Set the locale on each record in the SOQL result list.
C. Call the translate method on each record in the SOQL result list.
D. Use the Locale clause in the SOQL query.
Explanation:
When working with translated picklist values (including custom multi-select picklists) in SOQL, if you want to retrieve the label in the current user's language (as defined by the Translation Workbench), you must use the TO_LABEL() function in your SOQL query.
This function:
Converts the stored API value of the picklist field to the translated label.
Ensures the output is localized based on the user's language settings.
Example:
List
SELECT Name, TO_LABEL(Product__c)
FROM Account
WHERE Id IN :accountIds
];
This query returns the translated picklist values for Product__c in the current user's language.
The use of the transient keyword in Visualforce page controllers helps with which common performance issue?
A. Reduces load times
B. Improves page transfers
C. Reduces view state
D. Improves query performance
Explanation:
In Visualforce page controllers, the transient keyword is used to prevent certain variables from being saved in the view state. This helps with:
Reducing the size of the view state, which directly improves page performance and user experience.
Ensuring that non-critical or temporary data (like UI helper objects or temporary data containers) doesn't consume space in the view state.
The view state is a hidden form field in Visualforce pages that stores the state of the page between requests. If the view state grows too large (over 135 KB), it can lead to errors or slow performance.
Use Case:
public transient List
A Salesforce developer is hired by a multi-national company to build a custom
Lightning application that shows employees their employment benefits and earned
commissions over time. The application must acknowledge and respect the user's
locale context for dates, times, numbers, currency, and currency symbols.
When using Aura components, which approach should the developer implement to
ensure the Lightning application complies with the user's locale?
A. Use the $User global variable to retrieve the user preferences.
B. Use the $Label global value provider.
C. Use the $Lacale value provider to retrieve the user preferences.
D. Create a Hierarchical custom setting to store user preferences.
Explanation:
In Aura components, the $Locale global value provider gives access to the current user's locale-specific formatting preferences, such as:
Date and time formats
Number formats
Currency symbols
Decimal and grouping separators
This makes $Locale the correct tool for ensuring your Lightning application respects the user’s cultural and regional preferences, especially important for multi-national applications.
A developer created an Opportunity trigger that updates the account rating when an associated opportunity is considered high value. Current criteria for an opportunity
to be considered high value is an amount greater than or equal to $1,000,000. However, this criteria value can change over time.
There is a new requirement to also display high value opportunities in a Lightning web component.
Which two actions should the developer take to meet these business requirements, and also prevent the business logic that obtains the high value opportunities from
being repeated in more than one place?
Choose 2 answers
A. Call the trigger from the Lightning web component.
B. Create a helper class that fetches the high value opportunities,
C. Leave the business logic code inside the trigger for efficiency.
D. Use custom metadata to hold the high value amount.
Explanation:
B. Create a helper class that fetches the high value opportunities
This promotes code reuse and separation of concerns. By centralizing the logic in a helper class, both the Apex trigger and the Lightning Web Component (LWC) can call the same method to determine whether an Opportunity is high value. This avoids duplicating logic and ensures consistency across the application.
> This is a best practice in Apex design—keeping business logic out of triggers and encapsulating it in reusable classes.
D. Use custom metadata to hold the high value amount
Since the threshold for a "high value" Opportunity can change over time, storing it in custom metadata allows admins to update the value without modifying code or redeploying. Custom metadata is also accessible in Apex and can be deployed across environments, making it ideal for configuration data2.
An org has 2 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:
Why Option A is Correct?
Best Practice (DRY Principle):
Helper class centralizes the address normalization logic, avoiding code duplication in triggers.
Changes to normalization rules only need to be made in one place.
Modular & Maintainable:
Triggers handle the DML events (before insert/update).
Helper class (e.g., AddressService.cls) performs the actual normalization:
public class AddressService {
public static void normalizeAddress(SObject record) {
// Standardize street, city, postal code, etc.
record.put('Street', formatStreet(record.get('Street')));
// ... (other fields)
}
}
Trigger Example (Account):
trigger AccountTrigger on Account (before insert, before update) {
for (Account acc : Trigger.new) {
AddressService.normalizeAddress(acc);
}
}
Trigger Example (Contact):
trigger ContactTrigger on Contact (before insert, before update) {
for (Contact con : Trigger.new) {
AddressService.normalizeAddress(con);
}
}
Universal Containers allows customers to log into a Salesforce Community and update their orders via a custom Visualforce page. Universal Containers’ sales representatives can edit the orders on the same Visualforce page.
What should a developer use in an Apex test class to test that record sharing is enforced on the Visualforce page?
A. use System. profiles=() to test as a sales rep and a community user.
B. use System. profiles() to test as an administrator and a community user.
C. use System. profiles1h=() to test as a sales rep and a community user.
D. use System. runsAs () to test as an administrator and a community user.
Explanation:
To verify that record-level sharing rules are enforced correctly in Apex tests—especially when different user types (like internal sales reps and external community users) interact with the same Visualforce page—you need to simulate those users in your test context. That’s exactly what System.runAs() is designed for.
What System.runAs() does:
Executes code as a specific user, allowing you to test profile-based and sharing-based access.
Ensures that sharing rules, role hierarchy, and org-wide defaults are respected during test execution.
Essential for testing portal/community users, who often have restricted access.
Example:
@isTest
private class OrderSharingTest {
static testMethod void testCommunityUserAccess() {
User communityUser = [SELECT Id FROM User WHERE Profile.Name = 'Customer Community User' LIMIT 1];
System.runAs(communityUser) {
// Attempt to access or update Order__c record
// Assert access is correctly enforced
}
}
}
Business rules require a Contact ta always be created when a new Account is created.
What can be used when developing a custom screen to ensure an Account is not created if the creation of the Contact fails?
A. Use setSaverpoint (1) and rollback() with a try-catch block.
B. Use the Database. Insect method with a11orNone SEL LO alee,
C. Use the Database. Delete method if the Contact insertion fails.
D. Disable validation rules on Contacts and set default values with a trigger.
Explanation:
When creating multiple related records (like an Account and a required Contact), and you want to ensure atomicity (i.e., either both records are created or neither), you need transaction control.
The correct way to do this in Apex is by:
Creating a Savepoint before inserting the Account.
Attempting to insert both records in a try-catch block.
Rolling back to the Savepoint if any part fails (e.g., if Contact insertion fails).
Example:
Savepoint sp = Database.setSavepoint();
try {
insert newAccount;
insert newContact; // This must succeed
} catch (Exception ex) {
Database.rollback(sp); // Roll back both inserts
// Handle exception (e.g., log error, display message)
}
This guarantees that if the Contact insert fails, the Account won’t be created either — fulfilling the business requirement.
A company has many different unit test methods that create Account records as
part of their data setup. A new required field was added to the Account and now all
of the unit tests fail.
What is the optimal way for a developer to fix the issue?
A. Add the required field to the data setup for all of the unit tests.
B. Add a before insert trigger on Account to set the value of the required field,
C. Change the required field to be a validation rule that excludes the System Administrator profile.
D. Create a TestDataFactory class that serves as the single place to create Accounts for unit tests and set the required field there.
Explanation:
When your unit tests fail because a new required field was added to an object like Account, and many test methods are creating Account records, the optimal and scalable solution is to:
Centralize your test data creation in a TestDataFactory utility class.
Update the Account creation logic once in that class to include the required field.
Use that class in all test methods moving forward.
This approach:
Avoids duplicating test setup code in every test method.
Makes test code easier to maintain and update.
Follows the Single Responsibility Principle and Salesforce testing best practices.
An Apex class does not achieve expected code coverage. The testsetup method explicitly calls a method In the Apex class..
How can the developer generate the code coverage?
A. Use system.assert() in testSetup to verify the values are being returned.
B. Verify the user has permissions passing a user into System,.runds().
C. Call the Apex class method from a testsetup Instead of the testsetup methed.
D. Add @testvisible to the method in the class the developer is testing.
Explanation:
If an Apex class is not getting the expected code coverage, and the @testSetup method is calling the production method, that method’s logic does not contribute to code coverage.
This is because @testSetup methods are designed to set up test data only, and **code executed within them is not counted toward coverage metrics in Salesforce.
To generate proper coverage, you need to:
Move calls to the class/method outside the @testSetup method, into actual @isTest test methods.
If the method you want to test is private or not accessible in test classes, use the @TestVisible annotation to expose it for testing.
What @TestVisible does:
Makes private or protected methods/variables in Apex classes visible to test methods only.
Allows test classes to explicitly invoke and cover those methods.
Page 7 out of 17 Pages |
Previous |