Start tracking your progress
Trailhead Home
Trailhead Home

Understand New and Updated Apex Methods, Exceptions, and Interfaces

Learning Objectives

After completing this unit, you’ll be able to:

  • Use the new and updated Apex methods, exceptions, and interfaces.

Salesforce Certification—the Big Picture

Hey Trailblazer! If you hold the Salesforce Certified Platform Developer I credential, you need to complete this module to maintain your certification. 

If you are not certified and want to learn more, check out the Salesforce Certified Platform Developer I credential details. 

Note

Note

Although anyone can earn this badge, this module is designed for Salesforce Certified Platform Developer I certification maintenance. This level of knowledge and experience is assumed in the level of instruction provided.

Salesforce introduced several changes to Apex classes and methods in the Winter ’19 release. 

Apex: New and Changed Classes and Interfaces

Check out these new and updated Apex classes and interfaces.

Existing Apex Classes with New Methods

Schema.DescribeFieldResult Class

isAiPredictionField()

Returns a Boolean indicating whether the field is enabled to display Einstein prediction data.

Schema.DescribeSObjectResult Class

getRecordTypeInfosByDeveloperName()

Returns a map that matches developer names to their associated record type.

Schema.RecordTypeInfo Class

getDeveloperName()

Returns the developer name for this record type.

System.Crypto Class

verify(String algorithmName, Blob data, Blob signature, Blob publicKey)

Returns a Boolean verifying the digital signature for encrypted data, using the specified algorithm and the supplied public key.

verify(String algorithmName, Blob data, Blob signature, String certDevName)

Returns a Boolean verifying digital signatures for data, using the specified algorithm and the public key associated with the certDevName.

verifyMac(String algorithmName, Blob input, Blob privateKey, Blob macToVerify)

Returns a Boolean verifying the HMAC signature for data using the specified algorithm, input data, privateKey, and the MAC address.

System.Url Class

getOrgDomainUrl()

Returns the canonical URL for your org. For example, https://yourDomain.my.salesforce.com or, for orgs without My Domain enabled, https://yourInstance.salesforce.com.

Existing Apex Class with a Changed Method

System.UserInfo Class

getSessionId()

You can now use getSessionId() in asynchronous Apex (Batch, Future, Queueable, or Scheduled Apex). Previously, this method returned null when run asynchronously.

In asynchronous Apex, this method returns the session ID only when the code is run by an active, valid user. When the code is run by an internal user, such as the automated process user or a proxy user, the method returns null.

Changed Apex Enum

These enumerations are updated in the Winter ’19 release.

Auth.Auth.VerificationMethodEnum Enum

Contains the different ways users can identify themselves when logging in. Can be used to implement mobile-friendly passwordless login pages, and to self-register (and deregister) verification methods.

This enum has a new value, Password. Identity can be verified by password.

Metadata.PlatformActionListContextEnum Enum

Describes the different contexts of action lists.

This enum has a new value, ActionDefinition. This value is reserved for future use.

New Apex Exceptions

These exceptions are introduced in the Winter ’19 release.

Auth Namespace

LoginDiscoveryException

Throw an exception to indicate that an error occurred when executing the Login Discovery Handler.

DiscoveryCustomErrorException

Throw an exception to customize error messages that appear on login, verify, and self-registration pages.

New Apex Interfaces

These new interfaces are introduced in the Winter ’19 release.

Auth.ConfigurableSelfRegHandler Interface

Create a class that implements Auth.ConfigurableSelfRegHandler to register users with their email address or phone number instead of a username and password. When you set up your community’s self-registration with the Configurable Self-Reg Page, Salesforce generates a default AutocreatedConfigSelfReg Apex class. Modify the class to extend the functionality, for example, to change how users are created.

createUser(accountId, profileId, registrationAttributes, password)

Create a community member from the information that the visitor provided on your community’s self-registration page.

Auth.LoginDiscoveryHandler Interface

Create a class that implements Auth.LoginDiscoveryHandler to log in users based on other verification methods than username and password. Users can identify themselves with their email, phone number, or another identifier like a Federation ID or device identifier. When you set up your community’s login page with Login Discovery Page, Salesforce generates a default AutocreatedDiscLoginHandler. You can modify the class, for example, to support single sign-on (SSO).

login(identifier, startUrl, requestAttributes)

Log in the external user given the specified identifier, such as email or phone number. If successful, redirect the user to the community page specified by the start URL.

System.Callable Interface

Enables developers to use a common interface to build loosely coupled integrations between Apex classes or triggers, even for code in separate packages. Agreeing upon a common interface enables developers from different companies or different departments to build upon one another’s solutions. Implement this interface to enable the broader community, which might have different solutions than the ones you had in mind, to extend your code’s functionality.

call(action, args)

Provides functionality that other classes or packages can utilize and build upon.

Changed SOAP API Calls for Apex

The runTests() call has changed.

The RunTestsResult object includes two new fields.

flowCoverage

An array of results from test runs that executed flows.

flowCoverageWarnings

An array of warnings generated by test runs that executed flows.

retargeting