Salesforce Apex Practice Questions – Part 1

Share This Post

Here are a few beginner-level questions related to Salesforce Apex for you to practice:

  1. Create a new Apex class called “Calculator” with a method called “addNumbers” that takes two integer parameters and returns their sum. Test the method by calling it with sample values.
  2. Write an Apex class called “AccountHandler” that contains a method called “createAccount” which creates a new Account record with predefined values and inserts it into the database.
  3. Create a trigger on the Opportunity object that updates the “Stage” field to “Closed Won” when the Opportunity’s “Amount” field exceeds $100,000. Test the trigger by creating an Opportunity record and verifying the stage is updated correctly.
  4. Implement a method in Apex that accepts a list of Contact records and updates their email addresses to a specified value. Test the method with a list of sample Contact records.
  5. Write an Apex class called “LeadConverter” that converts a Lead record into an Account, Contact, and Opportunity record based on specific conditions. Implement a method called “convertLead” that performs the conversion logic. Test the method by creating a Lead record and converting it using the class.
  6. Create an Apex class called “StringManipulator” with a method called “reverseString” that takes a string as a parameter and returns the reversed string. Test the method with different input strings.
  7. Write an Apex class called “CaseHandler” that queries all Case records and prints the Case Number and Subject of each case. Use a for loop to iterate through the query results.
  8. Implement a method in Apex that accepts an Account Id as a parameter and returns the total number of related Contact records. Test the method with a sample Account Id.
  9. Write an Apex trigger on the Opportunity object that automatically updates the Close Date of an Opportunity to be one month ahead from the current date when the Opportunity Stage is changed to “Closed Won”. Test the trigger by creating an Opportunity record and changing its stage to “Closed Won”.
  10. Write an Apex class called “ContactProcessor” that queries all Contact records with a specific last name and updates their email address to a given value. Implement a method called “updateEmails” that takes the last name and new email address as parameters.
  11. Create a custom object called “Book__c” with fields “Title__c” (Text) and “Price__c” (Number). Write an Apex class called “BookHandler” that queries all Book records and calculates the average price of the books. Implement a method called “calculateAveragePrice” that returns the average price.
  12. Implement a method in Apex that accepts a List of Opportunity records and updates their Stage to “Closed Lost” if the Close Date is in the past. Test the method with a List of sample Opportunity records.
  13. Create a trigger on the Account object that automatically creates a new Contact record with a predefined value in the LastName field whenever a new Account is created. Test the trigger by creating a new Account record.
  14. Write an Apex class called “EmailSender” that sends an email to a specified recipient with a given subject and body. Implement a method called “sendEmail” that takes the recipient email address, subject, and body as parameters.
  15. Implement a scheduled Apex class called “OpportunityReminder” that runs every day and sends an email reminder for all open Opportunities whose Close Date is within 7 days. The email should contain the Opportunity Name, Close Date, and Account Name.
  16. Create an Apex class called “DivisionCalculator” with a method called “divideNumbers” that accepts two integers as parameters and performs the division operation. Handle the scenario where the second number is zero by throwing a custom exception called “DivideByZeroException”.
  17. Write a Batch Apex class called “AccountUpdater” that updates the “BillingCountry” field of all Account records to a specific value. The batch size should be 200 records per execution. Test the batch class by updating a large number of Account records.
  18. Create an Apex class called “ContactDeleter” with a method called “deleteContacts” that deletes all Contact records with a specific email domain. Implement the method to accept the email domain as a parameter.
  19. Write an Apex class called “LeadConverter” that converts a Lead record into an Account, Contact, and Opportunity record. Implement a method called “convertLead” that performs the conversion logic and returns the newly created Account Id.
  20. Create a trigger on the Case object that updates the “Status” field to “Escalated” when the Case Priority is set to “High”. Test the trigger by creating a Case record with a high priority.
  21. Implement a method in Apex that accepts a List of Opportunity records and calculates the total value of all opportunities. Return the sum of the opportunity amounts
  22. Write an Apex class called “CaseEscalator” that queries all Case records with a specific criteria and updates their “Status” field to “Escalated”.
  23. Create a custom object called “Product__c” with fields “Name” (Text) and “Price__c” (Number). Write an Apex class called “ProductHandler” that queries all Product records and calculates the average price. Implement a method called “calculateAveragePrice” that returns the average price.
  24. Implement a method in Apex that accepts a List of Lead records and updates their Status to “Qualified” if the Lead Source is “Web”.
  25. Create an Apex class called “EmailUtility” with a method called “sendBulkEmail” that sends a single email to multiple recipients. Implement the method to accept a List of email addresses as a parameter.
  26. Write an Apex class called “OpportunityValidator” that validates whether an Opportunity record meets certain criteria. Implement a method called “validateOpportunity” that returns true if the Opportunity is valid, and false otherwise.
  27. Implement a method in Apex that accepts an Account Id and returns the total number of related Opportunity records.
  28. Create a trigger on the Contact object that automatically assigns a default value to the “Title” field when a new Contact is created. Test the trigger by creating a new Contact record.
  29. Write an Apex class called “CaseHandler” that queries all Case records with a specific criteria and assigns them to a specified User. Implement a method called “assignCases” that accepts the criteria and User Id as parameters.
  30. Implement a method in Apex that accepts a List of Opportunity records and calculates the average Close Date. Return the average date as a result.
  31. Create an Apex class called “LeadAssigner” that assigns leads to specific users based on predefined criteria. Implement a method called “assignLeads” that performs the assignment logic and returns the number of leads assigned.
  32. Write an Apex class called “ContactCreator” that creates a new Contact record with predefined values and inserts it into the database. Implement a method called “createContact” to perform the creation and insertion.
  33. Implement a method in Apex that accepts a List of Account records and updates their “AnnualRevenue” field by applying a specified percentage increase.
  34. Create a trigger on the Opportunity object that automatically updates the “ExpectedRevenue” field when the Opportunity Amount is changed. The Expected Revenue should be calculated as 75% of the Amount.
  35. Write an Apex class called “TaskReminder” that queries all open Tasks with a specific due date and sends a reminder email to the task owner. Implement a method called “sendTaskReminder” to perform the email sending.
  36. Implement a method in Apex that accepts a List of Account records and checks if any of the Accounts have duplicate names. Return true if duplicates are found, and false otherwise.
  37. Create a custom object called “Project__c” with fields “Name” (Text) and “StartDate__c” (Date). Write an Apex class called “ProjectHandler” that queries all Project records and finds the project with the earliest start date. Implement a method called “findEarliestProject” that returns the project name.
  38. Implement a method in Apex that accepts a List of Contact records and filters out contacts with a specific status. Return the filtered list of contacts.
  39. Write an Apex class called “LeadDeduplicator” that queries all Lead records and identifies potential duplicates based on predefined criteria. Implement a method called “findDuplicates” that returns the count of potential duplicates.
  40. Create a trigger on the Account object that automatically updates the “LastModifiedDate” field of all related Contact records whenever the Account is updated.
  41. Implement a method in Apex that accepts a List of Opportunity records and checks if any of the Opportunities have an amount greater than a specified threshold. Return true if any opportunities exceed the threshold, and false otherwise.
  42. Write an Apex class called “CaseCommentHandler” that queries all Case Comment records and counts the number of comments for each Case. Implement a method called “countCaseComments” that returns a Map with Case Ids as keys and comment counts as values.
  43. Implement a method in Apex that accepts a List of Lead records and checks if any of the Leads have a specific Lead Source. Return true if any leads match the specified source, and false otherwise.
  44. Create an Apex class called “AccountHierarchyBuilder” that queries all Account records and builds a hierarchical structure based on the Parent Account field. Implement a method called “buildHierarchy” that returns a Map with Account Ids as keys and their child Account Ids as values.
  45. Implement a method in Apex that accepts a List of Contact records and updates their phone numbers to a specific value. Return the number of contacts that were updated.
  46. Write an Apex class called “AccountMergeHandler” that merges two Account records based on predefined rules. Implement a method called “mergeAccounts” that performs the merge logic and returns the merged Account Id.
  47. Create a trigger on the Opportunity object that automatically updates the “NextStep” field to “Follow-up” when the Opportunity Stage is changed to “Closed Lost”. Test the trigger by creating an Opportunity record and changing its stage to “Closed Lost”.
  48. Create an Apex class called “AccountCounter” that queries all Account records and counts the number of records. Implement a method called “countAccounts” that returns the count.
  49. Write an Apex class called “CaseStatusUpdater” that updates the “Status” field of all Case records to a specified value. Implement a method called “updateCaseStatus” to perform the update.
  50. Create a trigger on the Lead object that sets the “Converted” field to true when the Lead Status is set to “Closed – Converted”. Test the trigger by updating a Lead record status.
  51. Implement a method in Apex that accepts a List of Contact records and updates their “MailingCountry” field to a specified value. Return the number of contacts that were updated.
  52. Write an Apex class called “OpportunityOwnerChanger” that queries all Opportunity records and changes the owner to a specific User. Implement a method called “changeOpportunityOwner” to perform the owner change.
  53. Create a custom object called “Task__c” with fields “Subject” (Text) and “DueDate__c” (Date). Write an Apex class called “TaskHandler” that queries all Task records and finds the task with the latest due date. Implement a method called “findLatestTask” that returns the task subject.
  54. Implement a method in Apex that accepts a List of Lead records and checks if any of the Leads have a specific status. Return true if any leads match the specified status, and false otherwise.
  55. Create an Apex class called “CaseAssigner” that assigns cases to specific queues based on predefined criteria. Implement a method called “assignCasesToQueues” that performs the assignment logic and returns the number of cases assigned.
  56. Implement a method in Apex that accepts a List of Account records and filters out accounts with a specific industry. Return the filtered list of accounts.
  57. Write an Apex class called “ContactUpdater” that updates the “Phone” field of all Contact records to a specified value. Implement a method called “updateContactPhones” to perform the update.
  58. Create a trigger on the Opportunity object that calculates the “Probability” field based on the Opportunity Stage. Use predefined rules to assign the appropriate probability values.
  59. Implement a method in Apex that accepts a List of Lead records and checks if any of the Leads have an age greater than a specified value. Return true if any leads exceed the age threshold, and false otherwise.
  60. Write an Apex class called “CaseCommentCounter” that queries all Case Comment records and counts the number of comments for each Case. Implement a method called “countCaseComments” that returns a Map with Case Ids as keys and comment counts as values.
  61. Implement a method in Apex that accepts a List of Opportunity records and updates their “Description” field to a specific value. Return the number of opportunities that were updated.
  62. Create an Apex class called “AccountMerger” that merges two Account records based on predefined rules. Implement a method called “mergeAccounts” that performs the merge logic and returns the merged Account Id.
  63. Implement a method in Apex that accepts a List of Contact records and checks if any of the Contacts have a specific mailing state. Return true if any contacts match the specified state, and false otherwise.
  64. Write an Apex class called “OpportunityCalculator” that calculates the total value of all Opportunity records. Implement a method called “calculateTotalValue” that returns the sum of the opportunity amounts.
  65. Create a trigger on the Case object that updates the “Priority” field to “High” when the Case Origin is set to “Phone”. Test the trigger by creating a Case record with an origin of “Phone”.
  66. Implement a method in Apex that accepts a List of Lead records and updates their “Status” field to a specific value. Return the number of leads that were updated.
  67. Write an Apex class called “ContactDeactivator” that deactivates Contact records based on predefined criteria. Implement a method called “deactivateContacts” to perform the deactivation logic and return the number of contacts deactivated.
  68. Create an Apex class called “AccountHierarchyUpdater” that queries all Account records and updates their hierarchy based on the Parent Account field. Implement a method called “updateAccountHierarchy” to perform the update.
  69. Implement a method in Apex that accepts a List of Opportunity records and filters out opportunities with a specific stage. Return the filtered list of opportunities.
  70. Write an Apex class called “LeadStatusUpdater” that updates the “Status” field of all Lead records to a specified value. Implement a method called “updateLeadStatus” to perform the update.
  71. Create a trigger on the Account object that sets the “IsVIP__c” field to true when the Account Annual Revenue exceeds a specified threshold. Test the trigger by updating an Account record’s annual revenue.
  72. Implement a method in Apex that accepts a List of Contact records and checks if any of the Contacts have an email domain matching a specified pattern. Return true if any contacts match the pattern, and false otherwise.
  73. Write an Apex class called “OpportunityStageUpdater” that updates the Opportunity Stage to a specific value for all Opportunity records with a close date in the past. Implement a method called “updateOpportunityStages” to perform the update.
  74. Implement a method in Apex that accepts a List of Lead records and checks if any of the Leads have a specific lead source. Return true if any leads match the specified source, and false otherwise.
  75. Create an Apex class called “AccountDuplicator” that duplicates an existing Account record and creates a new record with the duplicated data. Implement a method called “duplicateAccount” that performs the duplication and returns the Id of the new Account.
  76. Implement a method in Apex that accepts a List of Opportunity records and calculates the average amount. Return the average amount as a result.
  77. Write an Apex class called “ContactNameUpdater” that updates the “FirstName” field of all Contact records with a specific last name. Implement a method called “updateContactNames” to perform the update.

Conclusion

I hope you like this blog and if you want any help let me know.

Stay tuned, there is way more to come! Follow me on LinkedIn, Instagram, and Twitter. So you won’t miss out on all future articles.

One Response

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe To Our Newsletter

Get updates and learn from the best

More To Explore

NetSuite Salesforce Integration: An Automation Guide

NetSuite Salesforce Integration is the seamless connection between NetSuite, a leading cloud-based Enterprise Resource Planning (ERP) system, and Salesforce, a premier Customer Relationship Management (CRM) platform.