Apex Basics and Database Hands-on Challenge

This is the Hands-on Challenge from the ThrailHead

Photo by Emile Perron on Unsplash

Apex Class and meathod

Create an Apex class with a method that returns an array (or list) of strings.

Create an Apex class with a method that returns an array (or list) of formatted strings (‘Test 0’, ‘Test 1’, …). The length of the array is determined by an integer parameter.

  1. The Apex class must be called StringArrayTest and be in the public scope
  2. The Apex class must have a public static method called generateStringArray
  • The generateStringArray method must return an array (or list) of strings
  • The method must accept an incoming Integer as a parameter, which will be used to determine the number of returned strings
  • The method must return a string value in the format Test n where n is the index of the current string in the array

Manipulate Records with DML

Create a method for inserting accounts.
To pass this challenge, create an Apex class that inserts a new account named after an incoming parameter. If the account is successfully inserted, the method should return the account record. If a DML exception occurs, the method should return null.

  1. The Apex class must be called AccountHandler and be in the public scope
  2. The Apex class must have a public static method called insertNewAccount
  • The method must accept an incoming string as a parameter, which will be used to create the Account name
  • The method must insert the account into the system and then return the record
  • The method must also accept an empty string, catch the failed DML and then return null

Write SOQL Queries

Create an Apex class that returns contacts based on incoming parameters.

For this challenge, you will need to create a class that has a method accepting two strings. The method searches for contacts that have a last name matching the first string and a mailing postal code matching the second. It gets the ID and Name of those contacts and returns them.

  1. The Apex class must be called ContactSearch and be in the public scope
  2. The Apex class must have a public static method called searchForContacts
  • The method must accept two incoming strings as parameters
  • The method should then find any contact that has a last name matching the first string, and mailing postal code (API name: MailingPostalCode) matching the second string
  • The method should finally return a list of Contact records of type List that includes the ID and Name fields

Write SOSL Queries

Create an Apex class that returns both contacts and leads based on a parameter.

To pass this challenge, create an Apex class that returns both contacts and leads that have first or last name matching the incoming parameter.

  1. The Apex class must be called ContactAndLeadSearch and be in the public scope
  2. The Apex class must have a public static method called searchContactsAndLeads
  • The method must accept an incoming string as a parameter
  • The method should then find any contact or lead that matches the string as part of either the first or last name
  • The method should finally use a return type of List<List< SObject>>

NOTE: Because SOSL indexes data for searching, you must create a Contact record and Lead record before checking this challenge. Both records must have the last name Smith. The challenge uses these records for the SOSL search

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store