Expressions and Operators – Exercises
Quiz Summary
0 of 21 Questions completed
Questions:
Information
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading…
You must sign in or sign up to start the quiz.
You must first complete the following:
Results
Results
0 of 21 Questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0)
Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)
Categories
- Not categorized 0%
-
Unfortunately, your results in the simulator were not up to the desired standards. 😔
However, take advantage of your unlimited access and continue to practice.
Remember, persistence and dedication will lead to mastery. 😎 -
Congratulations! 🎉
You have successfully passed the simulator and are now one step closer to achieving your certification.
We hope you will consider joining us again in your future certification journey.Wishing you the best of luck with the upcoming exam. Keep up the great work! 💪
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- Current
- Review
- Answered
- Correct
- Incorrect
-
Question 1 of 21
1. Question
Consider the scenario: You are creating a custom class that renames a given Account based on the provided old and new names. You have initialized the class but now you need to create an expression that checks if the old name is not equal to the new name.
Complete the following code fragment by filling in the blanks to create a conditional expression that checks if
oldAccountNameis not equal tonewAccountName.-
public class AccountRenamer {
String oldAccountName;
String newAccountName;
AccountRenamer(String oldName, String newName) {
oldAccountName = oldName;
newAccountName = newName;
}
public Boolean isDifferentName() {
return ;
}
}
CorrectIncorrect -
-
Question 2 of 21
2. Question
Imagine you’re creating a Salesforce application to manage books in a library. You want to store each book’s name and its unique ISBN number.
Fill in the blanks to create a new instance of a
Bookobject, initializing it with a title “Apex Programming” and its ISBN as “1234567890”.-
public class Book {
String title;
String ISBN;
Book(String bookTitle, String bookISBN) {
title = bookTitle;
ISBN = bookISBN;
}
}
Book myBook = ;
CorrectIncorrect -
-
Question 3 of 21
3. Question
A Salesforce developer is working on a feature to rename files in a custom application. They’ve created a class named
myRenamingClassthat takes in the old file name and the new desired file name to perform the renaming.Fill in the blanks below to instantiate this class for a file previously named “oldDocument.txt” and rename it to “newDocument.txt”:
-
myRenamingClass renamer = new ( , );
CorrectIncorrect -
-
Question 4 of 21
4. Question
You are working on a project where there is a need to create a map to store the relation between a company’s name and its yearly profit. Initialize the map and then add an entry for a company named “TechFirm” with a profit of 2 million (2000000).
Fill in the gaps:
-
Map< , > profitMap = new Map<String, Integer>();
profitMap.put( , );
CorrectIncorrect -
-
Question 5 of 21
5. Question
You are tasked with creating a new list of Accounts. In this list, you want to add two specific account instances: one with the
Nameof ‘EnterpriseCorp’ and another with theNameof ‘StartupHub’.Fill in the blanks to achieve this:
-
List<Account> companyAccounts = new <Account>();
companyAccounts.add(new Account(Name = ));
companyAccounts.add(new Account(Name = ));
CorrectIncorrect -
-
Question 6 of 21
6. Question
You are tasked with obtaining the primary email of a
Contactobject. In the past, to avoid null reference exceptions, you would check if the contact object and its email are not null. Convert the old way of checking for nulls into the new way using the safe navigation operator.Fill in the blanks:
-
// Previous code checking for nulls
String primaryEmail = null;
if (contact != null && contact.getEmail() != null) {
primaryEmail = contact.getEmail();
}// New code using the safe navigation operator
String primaryEmail = ;
CorrectIncorrect -
-
Question 7 of 21
7. Question
You’re working on a piece of code that extracts the address of a Contact object in Salesforce. You’re aware that sometimes the contact object or its getAddress() method could return null, and you want to safely navigate through these.
Complete the following lines of code:
-
// Previous method of checking for nulls
String contactAddress = null;
if (contact != null && contact.getAddress() != null) {
contactAddress = contact.getAddress();
}
// New method using the safe navigation operator
String contactAddress = ;
CorrectIncorrect -
-
Question 8 of 21
8. Question
You’re writing a piece of code where you need to extract the manager’s name from an
Employeeobject. There’s a possibility that an employee might not have a manager assigned, or the manager object might not have the name populated. Use the safe navigation operator to handle these cases gracefully.Fill in the blanks:
-
// Previous code checking for nulls
String managerName = null;
if (employee != null && employee.getManager() != null && employee.getManager().getName() != null) {
managerName = employee.getManager().getName();
}// Using the safe navigation operator
String managerName = ;
CorrectIncorrect -
-
Question 9 of 21
9. Question
You’re given the task of retrieving an email from a
Contactobject in Salesforce. Not all contacts might have an email populated. Use the safe navigation operator to ensure you don’t run into null reference exceptions.Complete the following:
-
// Traditional method of checking for nulls
String contactEmail = null;
if (contact != null && contact.getEmail() != null) {
contactEmail = contact.getEmail();
}
// Using the safe navigation operator
String contactEmail = ;
CorrectIncorrect -
-
Question 10 of 21
10. Question
As a developer, you’re building an approval workflow in Salesforce for invoice management. Before an invoice can be approved, its total amount must be less than or equal to the set budget limit.
Given an invoice amount of
500and a budget limit of750, fill in the blank to create the necessary condition for approval:-
Integer invoiceAmount = 500;
Integer budgetLimit = 750;
if (invoiceAmount budgetLimit) {
System.debug(‘Invoice can be approved’);
} else {
System.debug(‘Invoice exceeds budget limit’);
}
CorrectIncorrect -
-
Question 11 of 21
11. Question
You are developing a login function for a custom Salesforce application. Users are only allowed to log in if they have an active status (
isActive) and if their role is an “Admin” (userRole).Complete the following conditional check:
-
Boolean isActive = true;
String userRole = ‘Admin’;
Boolean canLogin;
canLogin = isActive (userRole == ‘Admin’);
CorrectIncorrect -
-
Question 12 of 21
12. Question
You’re developing a function to evaluate performance scores of sales reps in your Salesforce instance. If the sales rep’s score is not the same as the benchmark score of
85, a debug message should indicate that the sales rep didn’t meet the benchmark.Using the given variables, complete the conditional statement:
-
Integer repScore = 80;
Integer benchmarkScore = 85;
if (repScore benchmarkScore) {
System.debug(‘Sales rep did not meet the benchmark.’);
} else {
System.debug(‘Sales rep met the benchmark.’);
}
CorrectIncorrect -
-
Question 13 of 21
13. Question
In your Salesforce application, there’s a feature to automatically send a feedback request to users if they haven’t provided feedback yet. To implement this, you have to check if the
userFeedbackvariable is the same as the string ‘Not Given’.Fill in the blank to achieve this:
-
String userFeedback = ‘Not Given’;
if (userFeedback ‘Not Given’) {
System.debug(‘Send feedback request to the user.’);
} else {
System.debug(‘User has already provided feedback.’);
}
CorrectIncorrect -
-
Question 14 of 21
14. Question
You have a custom class
VIPCustomerin your Salesforce Org. Given an object instancecustomerObj, you want to check if it’s an instance of theVIPCustomerclass.Complete the expression to perform this check.
-
Object customerObj = new VIPCustomer();
Boolean isVIP;
isVIP = customerObj VIPCustomer;
// isVIP evaluates to true.
CorrectIncorrect -
-
Question 15 of 21
15. Question
You’re tracking the sales and refunds of a particular product. In one day, you sold 15 units of the product and had 5 units returned for a refund. Additionally, you gained an extra 10 units from another store’s stock.
Complete the expression to find out the final count of units you have after the transactions.
-
Integer unitsSold = 15;
Integer unitsReturned = 5;
Integer unitsReceived = 10;
Integer finalUnits;
finalUnits = unitsSold unitsReturned unitsReceived;
// The finalUnits count is 20.
CorrectIncorrect -
-
Question 16 of 21
16. Question
You are given a requirement where you must divide the total sales by the number of sales reps and then multiply it by a commission rate. The total sales are
5000, the number of sales reps is4, and the commission rate is10%.Fill in the blanks with the correct operators:
-
Integer totalSales = 5000;
Integer reps = 4;
Decimal commissionRate = 0.10;
Decimal commissionValue;
commissionValue = (totalSales reps) commissionRate;
CorrectIncorrect -
-
Question 17 of 21
17. Question
You’re given an Apex snippet that negates a Boolean value indicating if an online store is open. Additionally, you want to convert a given string representation of a number into an integer.
Fill in the blanks to achieve this:
-
Boolean storeIsOpen = true;
String strNumber = ‘100’;
Boolean storeIsClosed;
Integer convertedNumber;
storeIsClosed = storeIsOpen;
convertedNumber = ( )(strNumber);
System.debug(‘Store Closed Status: ‘ + storeIsClosed);
System.debug(‘Converted Number: ‘ + convertedNumber);
CorrectIncorrect -
-
Question 18 of 21
18. Question
You are given an Apex snippet that calculates the total items in the cart. Each time a new item is added, you need to increase the counter. However, before any calculation, you want to reset the counter to zero.
Fill in the blanks to ensure this:
-
Integer cartItems;
cartItems = ;
for(Integer i = 0; i < 5; i++) {
cartItems;
}
System.debug(‘Total items in cart: ‘ + cartItems);
CorrectIncorrect -
-
Question 19 of 21
19. Question
A customer initially buys a product for
$50. Due to a special offer, the customer gets an opportunity to buy another of the same product at half its price.Use the appropriate assignment operator to compute the new total cost for the customer:
-
Decimal productCost = 50;
Decimal specialOfferPrice = productCost / 2;
productCost specialOfferPrice;
System.debug(‘Total cost with special offer: ‘ + productCost);
CorrectIncorrect -
-
Question 20 of 21
20. Question
A customer has a total bill of
$100at a bookstore. If a promotional discount of$15is being offered for every purchase, adjust the customer’s total bill using the appropriate assignment operator:-
Decimal totalBill = 100;
totalBill 15;
System.debug(‘Total after discount: ‘ + totalBill);
CorrectIncorrect -
-
Question 21 of 21
21. Question
You’re developing an application to manage inventory. At the end of every day, the remaining items in stock are reduced by half due to expiration.
If the initial stock of an item is 80 units, fill in the blank to adjust the stock value to represent the remaining items:
-
Integer stock = 80;
stock 2;
System.debug(‘Stock left at the end of the day: ‘ + stock);
CorrectIncorrect -