Variables – Exercises
Quiz Summary
0 of 23 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 23 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
- 22
- 23
- Current
- Review
- Answered
- Correct
- Incorrect
-
Question 1 of 23
1. Question
You are building a Salesforce Apex utility class and you need to declare several variables: a boolean to determine if a user is active, an integer for the user’s age, and a map to relate Account IDs to Account Names.
-
isActiveUser = true;
userAge = 25;
Map< , > accountIdToName;
CorrectIncorrect -
-
Question 2 of 23
2. Question
In a Salesforce Apex class, you’re tasked with declaring a variable that can hold decimal values for storing product prices. Additionally, declare a string variable to store the product name and a list to store all product categories.
-
price = 19.99;
productName;
List< > productCategories;
CorrectIncorrect -
-
Question 3 of 23
3. Question
In an e-commerce system, you need to declare several variables: one to hold the product’s unique code, another to determine if a product is available in stock, and a set to store all unique tags associated with a product.
-
productCode;
isInStock = false;
Set< > productTags;
CorrectIncorrect -
-
Question 4 of 23
4. Question
You’re developing a system for a school, and you need to declare certain variables. The first one should keep track of the total number of students in a class. The second variable should store the name of the class teacher, and the third one, a list of all subjects taught in the class.
-
totalStudents = 30;
classTeacherName;
List< > subjects;
CorrectIncorrect -
-
Question 5 of 23
5. Question
You’re creating an e-commerce application and need to track products. Declare two variables: one to determine if the product is on sale and another to represent the discount rate applied to that product. The discount rate might be a percentage with decimal values, such as 10.5%.
-
isOnSale = true;
discountRate;
CorrectIncorrect -
-
Question 6 of 23
6. Question
You are developing a form for user registration. Declare two variables: one to hold the user’s email address and another to check if the user has opted to receive newsletters.
-
userEmail;
optedForNewsletter = false;
CorrectIncorrect -
-
Question 7 of 23
7. Question
Your application needs to track if a customer has opted into a newsletter. If their preference isn’t known, the system should not default to any value, leaving it undefined. Fill in the blanks to declare the variable that tracks this information:
-
hasOptedNewsletter = ;
CorrectIncorrect -
-
Question 8 of 23
8. Question
You are developing an application to track the bonus amount earned by employees. If no bonus is provided, it should be explicitly indicated as
nulluntil a value is assigned. Fill in the blanks to declare a variable to store the bonus amount:-
bonusAmount = ;
CorrectIncorrect -
-
Question 9 of 23
9. Question
You are developing a CRM system and need to capture the middle name of a user. However, not all users might have a middle name. Declare a variable to hold the middle name and ensure it does not have an initial value.
-
middleName = ;
CorrectIncorrect -
-
Question 10 of 23
10. Question
You are tasked with developing a system to track student enrollment dates for an online course. Initially, when a student account is created, the enrollment date is not set.
Fill in the blanks to declare the enrollment date variable and then, if the enrollment date is not set, assign today’s date as the default:
-
enrollmentDate;
if(enrollmentDate == ) {
enrollmentDate = .today();
}
CorrectIncorrect -
-
Question 11 of 23
11. Question
You’re building an application to manage event schedules. An event is planned, but the exact date hasn’t been set yet. However, you know that the event will likely happen 10 days before a known deadline. Fill in the blanks to declare the event date variable and calculate the tentative event date:
-
eventDate;
Date deadline = Date.today().addDays(20);
eventDate = deadline. (-10);
CorrectIncorrect -
-
Question 12 of 23
12. Question
You’re creating a CRM system, and you want to keep track of the last contact date with a customer. When a new customer is added, this date is undefined. Later, you want to add 30 days to the last contact date if it has been defined.
Fill in the blanks to achieve this:
-
lastContactDate;
if(lastContactDate != ) {
lastContactDate = lastContactDate. (30);
}
CorrectIncorrect -
-
Question 13 of 23
13. Question
You’re building a system to manage the release dates of software patches. For a new software patch, the release date might not be immediately decided. However, once you have a release date, you might want to delay it by 7 days if necessary.
Fill in the blanks to achieve this:
-
releaseDate;
if(releaseDate != ) {
releaseDate = releaseDate. (7);
}
CorrectIncorrect -
-
Question 14 of 23
14. Question
You are developing a reservation system for a hotel. When a reservation is first made, the check-in date is yet to be determined. Fill in the blanks to declare the check-in date variable and then, if the check-in date hasn’t been specified, set it to tomorrow’s date:
-
checkInDate;
if(checkInDate == ) {
checkInDate = .today(). (1);
}
CorrectIncorrect -
-
Question 15 of 23
15. Question
You are building an app to track whether a light in a smart home system is turned on or off. The default status of the light is off.
Fill in the blanks to declare the necessary variables and change the status if it hasn’t been set:
-
Boolean lightStatus = ;
lightChanged;
if(lightChanged == ) {
lightStatus = ;
}
CorrectIncorrect -
-
Question 16 of 23
16. Question
You are coding a system to track student scores in a quiz. Every student starts with a score of 0. However, bonus marks can be added for exceptional performance. Complete the blanks to declare the required variables and assign bonus marks if they haven’t been already set:
-
score = 0;
bonus;
if( == ) {
bonus = 5;
}
CorrectIncorrect -
-
Question 17 of 23
17. Question
You are developing an application for a simple quiz. The user’s score starts at
0. The number of questions the user has answered hasn’t been registered yet, and the total questions in the quiz are set to1. Also, a flag is needed to check if the user has started the quiz or not, but that flag isn’t set initially. Fill in the blanks to declare these variables:-
userScore = 0;
answeredQuestions;
totalQuestions = ;
hasStartedQuiz;
CorrectIncorrect -
-
Question 18 of 23
18. Question
Fill in the blanks to ensure correct variable declaration and scope in the provided code:
-
public class VariableExample2 {
m = 15;
public void sampleMethod() {
if(m > 10) {
n = m – 5;
System.debug(n);
}
o = 20;
System.debug(o);
}
}
CorrectIncorrect -
-
Question 19 of 23
19. Question
Given the below code snippet, fill in the blanks to ensure that the variables are correctly defined and scoped without any conflicts:
-
public class VariableExample1 {
classVariable = 25;
public void functionOne() {
localVariable = classVariable + 5;
System.debug(localVariable);
}
public void functionTwo() {
for( k = 0; k < 10; k++) {
System.debug(k);
}
}
}
CorrectIncorrect -
-
Question 20 of 23
20. Question
Given a need to store and manage data about a product’s price within a Salesforce Apex class, fill in the blanks to declare variables correctly ensuring the right scope is followed:
-
public class ProductPriceManager {
productPrice = 100;
public void discountCalculator() {
discountAmount = 10;
discountedPrice = productPrice – discountAmount;
System.debug(‘Discounted Price: ‘ + discountedPrice);
}
public void taxCalculator() {
taxRate = 0.05;
taxAmount = productPrice * taxRate;
System.debug(‘Tax Amount: ‘ + taxAmount);
}
}
CorrectIncorrect -
-
Question 21 of 23
21. Question
Consider a scenario where an Apex class manages user roles. Fill in the blanks to define variables with proper scope:
-
public class UserRoleManager {
defaultRole = ‘Guest’;
public void assignUserRole(String username) {
userRole;
if(username != null) {
roleAssignment = ‘Assigned’;
userRole = defaultRole;
System.debug(username + ‘ is ‘ + roleAssignment + ‘ the role: ‘ + userRole);
}
}
}
CorrectIncorrect -
-
Question 22 of 23
22. Question
Imagine you are developing an Apex class that monitors the battery level of devices. Fill in the blanks to correctly define and use the variables:
-
public class BatteryMonitor {
deviceName = ‘Laptop’;
public void batteryLevelLow() {
batteryLevel = 10;
alertMessage = deviceName + ‘ battery is at ‘ + batteryLevel + ‘%’;
System.debug(alertMessage);
}
public void batteryLevelHigh() {
batteryPercentage = 90;
System.debug(deviceName + ‘ battery is at ‘ + batteryPercentage + ‘%’);
}
}
CorrectIncorrect -
-
Question 23 of 23
23. Question
Suppose you are writing an Apex class that calculates an employee’s salary after considering bonuses.
Fill in the blanks to ensure variables are declared appropriately:
-
public class SalaryCalculator {
baseSalary = 50000;
public void calculateBonus() {
bonusPercentage = 0.1;
totalSalary = baseSalary + (baseSalary * bonusPercentage);
System.debug(‘Total Salary after bonus: ‘ + totalSalary);
}
public void calculateDeductions() {
deduction = 1000;
netSalary = baseSalary – deduction;
System.debug(‘Net Salary after deduction: ‘ + netSalary);
}
}
CorrectIncorrect -