System Class

Contains methods for system operations, such as writing debug messages and scheduling jobs.

System

The following are methods for System. All methods are static.

  • abortJob(jobId)

    Stops the specified job. If the job is currently executing, the stopped job is still visible in the job queue in the Salesforce user interface. The specified job is stopped, but any code that is in progress will continue to execute until it completes.

  • assert(condition, msg)

    Asserts that the specified condition is true. If it isn’t , a fatal error is returned that causes code execution to halt.

  • assertEquals(expected, actual, msg)

    Asserts that the first two arguments are the same. If they aren’t, a fatal error is returned that causes code execution to halt.

  • assertNotEquals(expected, actual, msg)

    Asserts that the first two arguments are different. If they’re the same, a fatal error is returned that causes code execution to halt.

  • attachFinalizer(finalizer)

    Attach a finalizer for a Queueable job.

  • currentPageReference()

    Returns a reference to the current page. This is used with Visualforce pages.

  • currentTimeMillis()

    Returns the current time in milliseconds, which is expressed as the difference between the current time and midnight, January 1, 1970 UTC.

  • debug(msg)

    Writes the specified message, in string format, to the execution debug log. The DEBUG log level is used.

  • debug(logLevel, msg)

    Writes the specified message, in string format, to the execution debug log with the specified log level.

  • enqueueJob(queueableObj)

    Adds a job to the Apex job queue that corresponds to the specified queueable class and returns the job ID.

  • enqueueJob(queueable, delay)

    Adds a job to the Apex job queue that corresponds to the specified queueable class and returns the job ID. The job is scheduled with a specified minimum delay (0–10 minutes). The delay is ignored during Apex testing.

  • enqueueJob(queueable, asyncOptions)

    Adds a job to the Apex job queue that corresponds to the specified queueable class and returns the job ID. Specify a unique signature for your queueable job, the maximum stack depth or the minimum queue delay in the asyncOptions parameter.

  • equals(obj1, obj2)

    Returns true if both arguments are equal. Otherwise, returns false.

  • getApplicationReadWriteMode()

    Returns the read write mode set for an organization during Salesforce.com upgrades and downtimes.

  • getQuiddityShortCode(QuiddityValue)

    Returns the short code for the Quiddity value of the current Request object.

  • hashCode(obj)

    Returns the hash code of the specified object.

  • isBatch()

    Returns true if a batch Apex job invoked the executing code, or false if not. In API version 35.0 and earlier, also returns true if a queueable Apex job invoked the code.

  • isFunctionCallback()

    Returns true if an asynchronous Salesforce Function callback invoked the executing code, or false if not. Available in API version 51.0 and later.

  • isFuture()

    Returns true if the currently executing code is invoked by code contained in a method annotated with future; false otherwise.

  • isQueueable()

    Returns true if a queueable Apex job invoked the executing code. Returns false if not, including if a batch Apex job or a future method invoked the code.

  • isRunningElasticCompute()

    Reserved for future use.

  • isScheduled()

    Returns true if the currently executing code is invoked by a scheduled Apex job; false otherwise.

  • movePassword(targetUserId,sourceUserId)

    Moves the specified user’s password to a different user.

  • now()

    Returns the current date and time in the GMT time zone.

  • pauseJobById(cronTriggerId)

    Pause a scheduled Apex job specified by its CronTrigger ID.

  • pauseJobByName(jobName)

    Pause a scheduled Apex job specified by its name.

  • process(workItemIds, action, comments, nextApprover)

    Processes the list of work item IDs.

  • purgeOldAsyncJobs(dt)

    Deletes asynchronous Apex job records for jobs that have finished execution before the specified date with a Completed, Aborted, or Failed status, and returns the number of records deleted.

  • purgeOldAsyncJobs(dt, numOfJobs)

    Deletes asynchronous Apex job records for the specified number of jobs that finished before the specified date and have a Completed, Aborted, or Failed status. Returns the number of records deleted.

  • requestVersion()

    Returns a two-part version that contains the major and minor version numbers of a package. Applies to first-generation managed packages.

  • resetPassword(userId, sendUserEmail)

    Resets the password for the specified user.

  • resetPasswordWithEmailTemplate(userId, sendUserEmail, emailTemplateName)

    Resets the user’s password and sends an email to the user with their new password. You specify the email template that is sent to the specified user. Use this method for external users of Experience Cloud sites.

  • resumeJobById(cronTriggerId)

    Resume a paused scheduled Apex job specified by its CronTrigger ID.

  • resumeJobByName(jobName)

    Resumes a paused scheduled Apex job specified by its name.

  • runAs(version)

    Changes the current package version to the package version specified in the argument.

  • runAs(userSObject)

    Changes the current user to the specified user.

  • schedule(jobName, cronExpression, schedulableClass)

    Use schedule with an Apex class that implements the Schedulable interface to schedule the class to run at the time specified by a Cron expression.

  • scheduleBatch(batchable, jobName, minutesFromNow)

    Schedules a batch job to run once in the future after the specified time interval and with the specified job name.

  • scheduleBatch(batchable, jobName, minutesFromNow, scopeSize)

    Schedules a batch job to run once in the future after the specified the time interval, with the specified job name and scope size. Returns the scheduled job ID (CronTrigger ID).

  • setPassword(userId, password)

    Sets the password for the specified user.

  • submit(workItemIds, comments, nextApprover)

    Submits the processed approvals. The current user is the submitter and the entry criteria is evaluated for all processes applicable to the current user.

  • today()

    Returns the current date in the current user’s time zone.

Stops the specified job. If the job is currently executing, the stopped job is still visible in the job queue in the Salesforce user interface. The specified job is stopped, but any code that is in progress will continue to execute until it completes.

public static Void abortJob(String jobId)

  • jobId:

    Type: String

    The jobId is the ID associated with an AsyncApexJob ID for batch or future Apex jobs, or a CronTrigger

    ID for scheduled Apex jobs. You can’t abort a scheduled Apex job using an AsyncApexJob ID.

Type: Void

The following methods return the job ID that can be passed to abortJob.

Asserts that the specified condition is true. If it isn’t , a fatal error is returned that causes code execution to halt.

We recommend that you use the methods of the Assert Class rather than this method. The System.Assert class provides methods that handle all types of logical assertions and comparisons, which improve the clarity of your Apex code.

public static Void assert(Boolean condition, Object msg)

  • condition:

    Type: Boolean

  • msg:

    Type: Object (Optional) Custom message returned as part of the error message.

Type: Void

You can’t catch an assertion failure using a try/catch block even though it’s logged as an exception.

Asserts that the first two arguments are the same. If they aren’t, a fatal error is returned that causes code execution to halt.

We recommend that you use the methods of the Assert Class rather than this method. The System.Assert class provides methods that handle all types of logical assertions and comparisons, which improve the clarity of your Apex code.

public static Void assertEquals(Object expected, Object actual, Object msg)

  • expected:

    Type: Object

    Specifies the expected value.

  • actual:

    Type:

    Object Specifies the actual value.

  • msg:

    Type:

    Object (Optional) Custom message returned as part of the error message.

Type: Void

You can’t catch an assertion failure using a try/catch block even though it’s logged as an exception.

Asserts that the first two arguments are different. If they’re the same, a fatal error is returned that causes code execution to halt.

We recommend that you use the methods of the Assert Class rather than this method. The System.Assert class provides methods that handle all types of logical assertions and comparisons, which improve the clarity of your Apex code.

public static Void assertNotEquals(Object expected, Object actual, Object msg)

  • expected:

    Type: Object

    Specifies the expected value.

  • actual:

    Type:

    Object Specifies the actual value.

  • msg:

    Type:

    Object (Optional) Custom message returned as part of the error message.

Type: Void

You can’t catch an assertion failure using a try/catch block even though it’s logged as an exception.

Attach a finalizer for a Queueable job.

public static void attachFinalizer(Object finalizer)

  • finalizer:

    Type:

    Object The instantiated class that implements the System.Finalizer interface.

Type: void

Returns a reference to the current page. This is used with Visualforce pages.

public static System.PageReference currentPageReference()

Type: System.PageReference

For more information, see PageReference Class.

Returns the current time in milliseconds, which is expressed as the difference between the current time and midnight, January 1, 1970 UTC.

public static Long currentTimeMillis()

Type: Long

Writes the specified message, in string format, to the execution debug log. The DEBUG log level is used.

public static Void debug(Object msg)

  • msg:

    Type: Object

Type: Void

If the msg argument is not a string, the debug method calls String.valueOf to convert it into a string. The String.valueOf method calls the toString method on the argument, if available, or any overridden toString method if the argument is a user-defined type. Otherwise, if no toString method is available, it returns a string representation of the argument.

If the log level for Apex Code is set to DEBUG or higher, the message of this debug statement will be written to the debug log.

Note that when a map or set is printed, the output is sorted in key order and is surrounded with square brackets ([]). When an array or list is printed, the output is enclosed in parentheses (()).

Calls to System.debug are not counted as part of Apex code coverage.Calls to System.debug are not counted as part of Apex code coverage.

For more information on log levels, see Debug Log Levels in the Salesforce online help.

Writes the specified message, in string format, to the execution debug log with the specified log level.

public static Void debug(LoggingLevel logLevel, Object msg)

  • logLevel:

    Type: LoggingLevel Enum

    The logging level to set for this method.

  • msg:

    Type:

    Object The message or object to write in string format to the execution debug log.

Type: Void

If the msg argument is not a string, the debug method calls String.valueOf to convert it into a string. The String.valueOf method calls the toString method on the argument, if available, or any overridden toString method if the argument is a user-defined type. Otherwise, if no toString method is available, it returns a string representation of the argument.

Calls to System.debug are not counted as part of Apex code coverage.

For more information on log levels, see Debug Log Levels in the Salesforce online help.

Adds a job to the Apex job queue that corresponds to the specified queueable class and returns the job ID.

public static ID enqueueJob(Object queueableObj)

Type: ID

The job ID, which corresponds to the ID of an AsyncApexJob record.

To add a job for asynchronous execution, call System.enqueueJob by passing in an instance of your class implementation of the Queueable interface for execution as follows:

For more information about Queueable Apex, including information about limits, see Queueable Apex.

Adds a job to the Apex job queue that corresponds to the specified queueable class and returns the job ID. The job is scheduled with a specified minimum delay (0–10 minutes). The delay is ignored during Apex testing.

public static Id enqueueJob(Object queueable, Integer delay)

  • queueable:

    Type:

    Object An instance of the class that implements the Queueable Interface.

  • delay:

    Type: Integer

    The minimum delay (0–10 minutes) before the queueable job is scheduled for execution. The delay is ignored during Apex testing.

    When you set the delay to 0 (zero), the Queueable job is run as quickly as possible. With chained queueable jobs, implement a mechanism to slow down or halt the job if necessary. Without such a fail-safe mechanism in place, you can rapidly reach the daily async Apex limit.

Type: Id

The job ID, which corresponds to the ID of an AsyncApexJob record.

This example adds a job for delayed asynchronous execution by passing in an instance of your class implementation of the Queueable interface for execution. There’s a minimum delay of 5 minutes before the job is executed.

For more information about Queueable Apex, including information about limits, see Queueable Apex.

Adds a job to the Apex job queue that corresponds to the specified queueable class and returns the job ID. Specify a unique signature for your queueable job, the maximum stack depth or the minimum queue delay in the asyncOptions parameter.

public static Id enqueueJob(Object queueable, Object asyncoptions)

  • queueable:

    Type:

    Object An instance of the class that implements the Queueable Interface.

  • asyncoptions:

    Type: AsyncOptions

    Specify

    a unique signature for your queueable job, the maximum stack depth, or a minimum queue delay in the AsyncOptions class properties.

Type: Id

The job ID, which corresponds to the ID of an AsyncApexJob record.

The System.AsyncInfo class methods help you determine if maximum stack depth is set in your Queueable request and get the stack depths and queue delay for queueables that are currently running. Use information about the current queueable execution to make decisions on adjusting delays on subsequent calls.

These are methods in the System.AsyncInfo class.

  • hasMaxStackDepth()
  • getCurrentQueueableStackDepth()
  • getMaximumQueueableStackDepth()
  • getMinimumQueueableDelayInMinutes()

For more information about Queueable Apex, including information about limits, see Queueable Apex.

Returns true if both arguments are equal. Otherwise, returns false.

public static Boolean equals(Object obj1, Object obj2)

  • obj1:

    Type:

    Object Object being compared.

  • obj2:

    Type:

    Object Object to compare with the first argument.

Type: Boolean

obj1 and obj2 can be of any type. They can be values, or object references, such as sObjects and user-defined types.

The comparison rules for System.equals are identical to the ones for the == operator. For example, string comparison is case insensitive. For information about the comparison rules, see the == operator.

Returns the read write mode set for an organization during Salesforce.com upgrades and downtimes.

public static System.ApplicationReadWriteMode getApplicationReadWriteMode()

Type: System.ApplicationReadWriteMode

Valid values are:

  • DEFAULT
  • READ_ONLY

Use the System.ApplicationReadWriteMode enum returned by the getApplicationReadWriteMode to programmatically determine if the application is in read-only mode during Salesforce upgrades and downtimes.

Valid values for the enum are:

  • DEFAULT

  • READ_ONLY

Example:

Returns the short code for the Quiddity value of the current Request object.

public String getQuiddityShortCode(System.Quiddity QuiddityValue)

  • QuiddityValue:

    Type: System.Quiddity

    The Quiddity enum value that has an associated short code. This short code is used in Event Monitoring logs. For more information, see Apex Execution Event Type.

Type: String

Returns the hash code of the specified object.

public static Integer hashCode(Object obj)

  • obj:

    Type:

    Object The object to get the hash code for. This parameter can be of any type, including values or object references, such as sObjects or user-defined types.

Type: Integer

In API version 51.0 and later, the hashCode() method returns the same hashCode for identical Id values. In API version 50.0 and earlier, identical Id values didn’t always generate the same hashCode value.

Returns true if a batch Apex job invoked the executing code, or false if not. In API version 35.0 and earlier, also returns true if a queueable Apex job invoked the code.

public static Boolean isBatch()

Type: Boolean

A batch Apex job can’t invoke a future method. Before invoking a future method, use isBatch() to check whether the executing code is a batch Apex job.

Returns true if an asynchronous Salesforce Function callback invoked the executing code, or false if not. Available in API version 51.0 and later.

public static Boolean isFunctionCallback()

Type: Boolean

Use this method to determine if the Apex code is being invoked as part of a callback from an asynchronous Salesforce Functions invocation. For more details on invoking Salesforce Functions from Apex, see Functions Namespace.

Returns true if the currently executing code is invoked by code contained in a method annotated with future; false otherwise.

public static Boolean isFuture()

Type: Boolean

Since a future method can’t be invoked from another future method, use this method to check if the current code is executing within the context of a future method before you invoke a future method.

Returns true if a queueable Apex job invoked the executing code. Returns false if not, including if a batch Apex job or a future method invoked the code.

public static Boolean isQueueable()

Type: Boolean

Reserved for future use.

public static Boolean isRunningElasticCompute()

Type: Boolean

Returns true if the currently executing code is invoked by a scheduled Apex job; false otherwise.

public static Boolean isScheduled()

Type: Boolean

Moves the specified user’s password to a different user.

public static Void movePassword(ID targetUserId, ID sourceUserId)

  • targetUserId:

    Type: ID

    The user that the password is moved to.

  • sourceUserId:

    Type: ID

    The user that the password is moved from.

Type: Void

Moving a password simplifies converting a user to another type of user, such as when converting an external user to a user with less restrictive access. If you require access to the movePassword method, contact Salesforce.

Keep in mind these requirements.

  • The targetUserId, sourceUserId, and user performing the move operation must all belong to the same Salesforce org.
  • The targetUserId and the sourceUserId cannot be the same as the user performing the move operation.
  • A user without a password can’t be specified as the sourceUserId. For example, a source user who has already had their password moved is left without a password. That user can’t be a source user again.

After the password is moved:

  • The target user can log in with the password.
  • The source user no longer has a password. To enable logins for this user, a password reset is required.

Returns the current date and time in the GMT time zone.

public static Datetime now()

Type: Datetime

Pause a scheduled Apex job specified by its CronTrigger ID.

public static void pauseJobById(String cronTriggerId)

  • cronTriggerId:

    Type: String

    The scheduled job ID.

Type: void

Pause a scheduled Apex job specified by its name.

public static void pauseJobByName(String jobName)

Type: void

Processes the list of work item IDs.

public static List<Id> process(List<Id> workItemIds, String action, String comments, String nextApprover)

Type: List<Id>

Deletes asynchronous Apex job records for jobs that have finished execution before the specified date with a Completed, Aborted, or Failed status, and returns the number of records deleted.

public static Integer purgeOldAsyncJobs(Date dt)

  • dt:

    Type: Date

    Specifies the date up to which old records are deleted. The date comparison is based on the CompletedDate field of AsyncApexJob, which is in the GMT time zone.

Type: Integer

Asynchronous Apex job records are records in AsyncApexJob.

The system cleans up asynchronous job records for jobs that have finished execution and are older than seven days. You can use this method to further reduce the size of AsyncApexJob by cleaning up more records.

Each execution of this method counts as a single row against the governor limit for DML statements.

This example shows how to delete all job records for jobs that have finished before today’s date.

Deletes asynchronous Apex job records for the specified number of jobs that finished before the specified date and have a Completed, Aborted, or Failed status. Returns the number of records deleted.

public static Integer purgeOldAsyncJobs(Date dt, Integer numOfJobs)

  • dt:

    Type: Date

    Specifies the date up to which old records are deleted. The date comparison is based on the CompletedDate field of AsyncApexJob, which is in the GMT time zone.

  • numOfJobs:

    Type: Integer

    Specifies the maximum number of async jobs to delete, starting from the oldest job that finished before the specified date.

Type: Integer

Asynchronous Apex job records are records in AsyncApexJob.

The system purges asynchronous job records for jobs that have finished execution and are older than seven days. You can use this method to further reduce the size of AsyncApexJob by purging more records.

Each execution of this method counts as a single row against the governor limit for DML statements.

This example shows how to delete up to 1000 job records for jobs that finished before today’s date.

Returns a two-part version that contains the major and minor version numbers of a package. Applies to first-generation managed packages.

public static System.Version requestVersion()

Type: System.Version

Using this method, you can determine the version of an installed instance of your package from which the calling code is referencing your package. Based on the version that the calling code has, you can customize the behavior of your package code. See Version Apex Code Behavior in the Apex Developer Guide.

The requestVersion method isn’t supported for unmanaged packages. If you call it from an unmanaged package, an exception will be thrown.

Resets the password for the specified user.

public static System.ResetPasswordResult resetPassword(ID userId, Boolean sendUserEmail)

  • userId:

    Type: ID

  • sendUserEmail:

    Type: Boolean

Type: System.ResetPasswordResult

When the user logs in with the new password, they are prompted to enter a new password, and to select a security question and answer if they haven’t already. If you specify true for sendUserEmail, the user is sent an email notifying them that their password was reset. A link to sign onto Salesforce using the new password is included in the email. Use setPassword(userId, password) if you don’t want the user to be prompted to enter a new password when they log in.

Be careful with this method, and do not expose this functionality to end-users.

Resets the user’s password and sends an email to the user with their new password. You specify the email template that is sent to the specified user. Use this method for external users of Experience Cloud sites.

public static System.ResetPasswordResult resetPasswordWithEmailTemplate(Id userId, Boolean sendUserEmail, String emailTemplateName)

  • userId:

    Type: Id

    The ID of the user whose password was reset.

  • sendUserEmail:

    Type: Boolean

  • emailTemplateName:

    Type: String

    Name of the email template.

Type: System.ResetPasswordResult

If you specify true for sendUserEmail, specify the email template that is sent to the user notifying them that their password was reset. When the user logs in with the new password in the email, they are prompted to enter a new password. A link to sign onto Salesforce using the new password is included in the email. Use setPassword(userId, password) if you don’t want the user to be prompted to enter a new password when they log in.

The password reset process doesn’t verify an external user’s email address.

Be careful with this method, and do not expose this functionality to end-users.

Resume a paused scheduled Apex job specified by its CronTrigger ID.

public static void resumeJobById(String cronTriggerId)

  • cronTriggerId:

    Type: String

    The scheduled job ID.

Type: void

If you resume a paused scheduled job, the job immediately runs one time. Subsequent executions of the job run according to the established schedule. Any scheduled executions that were missed while the job was paused don’t run.

Resumes a paused scheduled Apex job specified by its name.

public static void resumeJobByName(String jobName)

Type: void

If you resume a paused scheduled job, the job immediately runs one time. Subsequent executions of the job run according to the established schedule. Any scheduled executions that were missed while the job was paused don’t run.

Changes the current package version to the package version specified in the argument.

public static Void runAs(System.Version version)

Type: Void

A package developer can use Version methods to continue to support existing behavior in classes and triggers in previous package versions while continuing to evolve the code. Apex classes and triggers are saved with the version settings for each installed managed package that the class or trigger references.

This method is used for testing your component behavior in different package versions that you upload to the AppExchange. This method effectively sets a two-part version consisting of major and minor numbers in a test method so that you can test the behavior for different package versions.

You can only use runAs in a test method. There is no limitation to the number of calls to this method in a transaction. For sample usage of this method, see Testing Behavior in Package Versions.

Changes the current user to the specified user.

public static Void runAs(User userSObject)

  • userSObject:

    Type: User

Type: Void

All of the specified user’s record sharing is enforced during the execution of runAs. You can only use runAs in a test method. For more information, see Using the runAs() Method.

The runAs method ignores user license limits. You can create new users with runAs even if your organization has no additional user licenses.

The runAs method implicitly inserts the user that is passed in as parameter if the user has been instantiated, but not inserted yet.

You can also use runAs to perform mixed DML operations in your test by enclosing the DML operations within the runAs block. In this way, you bypass the mixed DML error that is otherwise returned when inserting or updating setup objects together with other sObjects. See sObjects That Cannot Be Used Together in DML Operations.

Every call to runAs counts against the total number of DML statements issued in the process.

Use schedule with an Apex class that implements the Schedulable interface to schedule the class to run at the time specified by a Cron expression.

public static String schedule(String jobName, String cronExpression, Object schedulableClass)

  • jobName:

    Type: String

  • cronExpression:

    Type: String

  • schedulableClass:

    Type: Object

Type: String

Returns the scheduled job ID (CronTrigger ID).

Use extreme care if you’re planning to schedule a class from a trigger. You must be able to guarantee that the trigger won’t add more scheduled classes than the limit. In particular, consider API bulk updates, import wizards, mass record changes through the user interface, and all cases where more than one record can be updated at a time. Use the abortJob method to stop the job after it has been scheduled.

Salesforce schedules the class for execution at the specified time. Actual execution may be delayed based on service availability.

After you implement a class with the Schedulable interface, use the System.Schedule method to execute it. The scheduler runs as system—all classes are executed, whether or not the user has permission to execute the class.

Use extreme care if you’re planning to schedule a class from a trigger. You must be able to guarantee that the trigger won’t add more scheduled classes than the limit. In particular, consider API bulk updates, import wizards, mass record changes through the user interface, and all cases where more than one record can be updated at a time.

The System.Schedule method takes three arguments: a name for the job, an expression used to represent the time and date the job is scheduled to run, and the name of the class. This expression has the following syntax:

Salesforce schedules the class for execution at the specified time. Actual execution may be delayed based on service availability. The System.Schedule method uses the user’s timezone for the basis of all schedules.

The following are the values for the expression:

NameValuesSpecial Characters
Seconds0–59None
Minutes0–59None
Hours0–23, - * /
Day_of_month1–31, - * ? / L W
Month1–12 or the following:
  • JAN
  • FEB
  • MAR
  • APR
  • MAY
  • JUN
  • JUL
  • AUG
  • SEP
  • OCT
  • NOV
  • DEC
, - * /
Day_of_week1–7 or the following:
  • SUN
  • MON
  • TUE
  • WED
  • THU
  • FRI
  • SAT
, - * ? / L #
optional_yearnull or 1970–2099, - * /

The special characters are defined as follows:

Special CharacterDescription
,Delimits values. For example, use JAN, MAR, APR to specify more than one month.
-Specifies a range. For example, use JAN-MAR to specify more than one month.
*Specifies all values. For example, if Month is specified as *, the job is scheduled for every month.
?Specifies no specific value. This is only available for Day_of_month and Day_of_week, and is generally used when specifying a value for one and not the other.
/Specifies increments. The number before the slash specifies when the intervals will begin, and the number after the slash is the interval amount. For example, if you specify 1/5 for Day_of_month, the Apex class runs every fifth day of the month, starting on the first of the month.
LSpecifies the end of a range (last). This is only available for Day_of_month and Day_of_week. When used with Day of month, L always means the last day of the month, such as January 31, February 29 for leap years, and so on. When used with Day_of_week by itself, it always means 7 or SAT. When used with a Day_of_week value, it means the last of that type of day in the month. For example, if you specify 2L, you are specifying the last Monday of the month. Do not use a range of values with L as the results might be unexpected.
WSpecifies the nearest weekday (Monday-Friday) of the given day. This is only available for Day_of_month. For example, if you specify 20W, and the 20th is a Saturday, the class runs on the 19th. If you specify 1W, and the first is a Saturday, the class does not run in the previous month, but on the third, which is the following Monday.
#Specifies the nth day of the month, in the format weekday#day_of_month. This is only available for Day_of_week. The number before the # specifies weekday (SUN-SAT). The number after the # specifies the day of the month. For example, specifying 2#1 means the class runs on the first Monday of every month.

Use the L and W together to specify the last weekday of the month.

The following are some examples of how to use the expression.

ExpressionDescription
0 0 13 * * ?Class runs every day at 1 PM.
0 0 22 ? * 6LClass runs the last Friday of every month at 10 PM.
0 0 10 ? * MON-FRIClass runs Monday through Friday at 10 AM.
0 0 20 * * ? 2010Class runs every day at 8 PM during the year 2010.

In the following example, the class proschedule implements the Schedulable interface. The class is scheduled to run at 8 AM, on the 13 February.

Schedules a batch job to run once in the future after the specified time interval and with the specified job name.

public static String scheduleBatch(Database.Batchable batchable, String jobName, Integer minutesFromNow)

  • batchable:

    Type: Database.Batchable

    An instance of a class that implements the Database.Batchable interface.

  • jobName:

    Type: String

    The name of the job that this method will start.

  • minutesFromNow:

    Type: Integer

    The time interval in minutes after which the job should start executing. This argument must be greater than zero.

Type: String

The scheduled job ID (CronTrigger ID).

Some things to note about System.scheduleBatch:

  • When you call System.scheduleBatch, Salesforce schedules the job for execution at the specified time. Actual execution occurs at or after that time, depending on service availability.
  • The scheduler runs as system—all classes are executed, whether the user has permission to execute the class or not.
  • When the job’s schedule is triggered, the system queues the batch job for processing. If Apex flex queue is enabled in your org, the batch job is added at the end of the flex queue. For more information, see Holding Batch Jobs in the Apex Flex Queue.
  • All scheduled Apex limits apply for batch jobs scheduled using System.scheduleBatch. After the batch job is queued (with a status of Holding or Queued), all batch job limits apply and the job no longer counts toward scheduled Apex limits.
  • After calling this method and before the batch job starts, you can use the returned scheduled job ID to abort the scheduled job using the System.abortJob method.

For an example, see Using Batch Apex.

Schedules a batch job to run once in the future after the specified the time interval, with the specified job name and scope size. Returns the scheduled job ID (CronTrigger ID).

public static String scheduleBatch(Database.Batchable batchable, String jobName, Integer minutesFromNow, Integer scopeSize)

  • batchable:

    Type: Database.Batchable

    The batch class that implements the Database.Batchable interface.

  • jobName:

    Type: String

    The name of the job that this method will start.

  • minutesFromNow:

    Type: Integer

    The time interval in minutes after which the job should start executing.

  • scopeSize:

    Type: Integer

    The number of records that should be passed to the batch execute method.

Type: String

Some things to note about System.scheduleBatch:

  • When you call System.scheduleBatch, Salesforce schedules the job for execution at the specified time. Actual execution occurs at or after that time, depending on service availability.
  • The scheduler runs as system—all classes are executed, whether the user has permission to execute the class or not.
  • When the job’s schedule is triggered, the system queues the batch job for processing. If Apex flex queue is enabled in your org, the batch job is added at the end of the flex queue. For more information, see Holding Batch Jobs in the Apex Flex Queue.
  • All scheduled Apex limits apply for batch jobs scheduled using System.scheduleBatch. After the batch job is queued (with a status of Holding or Queued), all batch job limits apply and the job no longer counts toward scheduled Apex limits.
  • After calling this method and before the batch job starts, you can use the returned scheduled job ID to abort the scheduled job using the System.abortJob method.

For an example, see Using the System.scheduleBatch Method.

Sets the password for the specified user.

public static Void setPassword(ID userId, String password)

  • userId:

    Type: ID

  • password:

    Type: String

Type: Void

  • If a security question hasn’t been previously configured, a user who logs in with a new password that was set using setPassword() is redirected to the “Change Your Password” page.
  • Use resetPassword(userId, sendUserEmail) if you want the user to go through the reset process and create their own password.

Be careful with this method, and don’t expose this functionality to end users.

Submits the processed approvals. The current user is the submitter and the entry criteria is evaluated for all processes applicable to the current user.

public static List<ID> submit(List<ID> workItemIds, String comments, String nextApprover)

Type: List<ID>

For enhanced submit and evaluation features, see the ProcessSubmitRequest class.

Returns the current date in the current user’s time zone.

public static Date today()

Type: Date