Here are a few beginner-level questions related to Salesforce Apex for you to practice:
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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”.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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”.
- 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.
- 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.
- 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.
- 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.
- 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
- Write an Apex class called “CaseEscalator” that queries all Case records with a specific criteria and updates their “Status” field to “Escalated”.
- 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.
- Implement a method in Apex that accepts a List of Lead records and updates their Status to “Qualified” if the Lead Source is “Web”.
- 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.
- 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.
- Implement a method in Apex that accepts an Account Id and returns the total number of related Opportunity records.
- 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.
- 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.
- 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.
- 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.
- 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.
- Implement a method in Apex that accepts a List of Account records and updates their “AnnualRevenue” field by applying a specified percentage increase.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- Create a trigger on the Account object that automatically updates the “LastModifiedDate” field of all related Contact records whenever the Account is updated.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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”.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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”.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- Implement a method in Apex that accepts a List of Opportunity records and calculates the average amount. Return the average amount as a result.
- 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
I am continually searching online for ideas that can help me. Thanks!