Initiate Two-Factor Authentication with Apex

Initiate your two-factor authentication process with two new Apex methods in the System.UserManagement class. To verify a user’s identity with email, phone (SMS), or Salesforce Authenticator verification, pair the methods—one to initiate a verification service and one to complete the verification service. For password or time-based one-time password (TOTP) verification, you can use the second method alone to provide a complete verification service.

Where: This change applies to Lightning Experience and Salesforce Classic in Essentials, Contact Manager, Group, Professional, Enterprise, Performance, Unlimited, and Developer editions.

How: Depending on the type of verification, use one or both of these Apex methods.
  • System.UserManagement.initVerificationMethod
  • System.UserManagement.verifyVerificationMethod