Step-by-Step Guide to Create the Application
✅ Step 1: Log in to Salesforce
• Go to https://login.salesforce.com.
• Log in with your credentials.
• Ensure you are in a Developer Edition or Sandbox environment.
2. After Logging In:
• You will be on the Salesforce Setup/Home page (not Trailhead).
• At the top-right corner of the screen, click on your avatar/profile picture.
• Select Developer Console from the dropdown.
🛠️ This will open a new window called Developer Console, where you can write and execute Apex
code.
Step 3: Create an Apex Class
1. In Developer Console:
o Click File > New > Apex Class.
Sabke class ka naam alag hoga niche wala addition ka hai…
o Name it: AddTwoNumbers.
2. Paste the following code: jo bhi code mila ho addition , substraction,
multiplication……
public class AddTwoNumbers {
// Method to add two numbers
public static Integer add(Integer a, Integer b) {
return a + b;
Step 4: Create an Apex Anonymous Block to Run the Code
1. In Developer Console:
o Click Debug > Open Execute Anonymous Window.
2. Paste the following code:
Integer result = AddTwoNumbers.add(10, 15);
System.debug('The result is: ' + result);
Step 5: View the Result
• In the Logs tab:
o Open the latest log.
o Use Ctrl+F to search for USER_DEBUG.
13. Subtraction of Two Numbers
public class SubtractionDemo {
public static Integer subtract(Integer a, Integer b) {
return a - b;
}
}
Execute:
Integer result = SubtractionDemo.subtract(20, 5);
System.debug('Subtraction result: ' + result);
14. Multiplication of Two Numbers
public class MultiplicationDemo {
public static Integer multiply(Integer a, Integer b) {
return a * b;
}
}
Execute:
Integer result = MultiplicationDemo.multiply(4, 6);
System.debug('Multiplication result: ' + result);
15. Division of Two Numbers
public class DivisionDemo {
public static Decimal divide(Decimal a, Decimal b) {
if (b != 0) {
return a / b;
} else {
return null;
}
}
}
Execute:
Decimal result = DivisionDemo.divide(10, 2);
System.debug('Division result: ' + result);
16. Add, Subtract, Multiply, Divide Together
public class AllOperations {
public static void calculate(Integer a, Integer b) {
System.debug('Addition: ' + (a + b));
System.debug('Subtraction: ' + (a - b));
System.debug('Multiplication: ' + (a * b));
if (b != 0) {
System.debug('Division: ' + (Decimal.valueOf(a) / b));
} else {
System.debug('Division: Cannot divide by zero');
}
}
}
Execute:
AllOperations.calculate(20, 4);
17. Display Multiples of 5 (Table of 5)
public class TableOfFive {
public static void display() {
for (Integer i = 1; i <= 10; i++) {
System.debug('5 x ' + i + ' = ' + (5 * i));
}
}
}
Execute:
TableOfFive.display();
18. Display Multiples of 10 (Table of 10)
public class TableOfTen {
public static void display() {
for (Integer i = 1; i <= 10; i++) {
System.debug('10 x ' + i + ' = ' + (10 * i));
}
}
}
Execute:
TableOfTen.display();
19. Print a Welcome Message
public class WelcomeMessage {
public static void showMessage() {
System.debug('Welcome to Apex Programming Language of Salesforce
Platform');
}
}
Execute:
WelcomeMessage.showMessage();