The following are methods for System. All methods are static.
public static Void abortJob(String jobId)
Type: Void
The following methods return the job ID that can be passed to abortJob.
public static Void assert(Boolean condition, Object msg)
Type: Void
public static Void assertEquals(Object expected, Object actual, Object msg)
Type: Void
You can’t catch an assertion failure using a try/catch block even though it is logged as an exception.
public static Void assertNotEquals(Object expected, Object actual, Object msg)
Type: Void
You can’t catch an assertion failure using a try/catch block even though it is logged as an exception.
public static System.PageReference currentPageReference()
Type: System.PageReference
For more information, see PageReference Class.
public static Long currentTimeMillis()
Type: Long
public static Void debug(Object msg)
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.
For more information on log levels, see “Debug Log Levels” in the Salesforce online help.
public static Void debug(LoggingLevel logLevel, Object msg)
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.
Use the loggingLevel enum to specify the logging level for the debug method.
Log levels are cumulative. For example, if the lowest level, ERROR, is specified for Apex Code, only debug methods with the log level of ERROR are logged. If the next level, WARN, is specified, the debug log contains debug methods specified as either ERROR or WARN.
In the following example, the string MsgTxt is not written to the debug log because the log level is ERROR and the debug method has a level of INFO:
System.LoggingLevel level = LoggingLevel.ERROR;
System.debug(logginglevel.INFO, 'MsgTxt');
For more information on log levels, see “Debug Log Levels” in the Salesforce online help.
public static ID enqueueJob(Object queueableObj)
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:
ID jobID = System.enqueueJob(new MyQueueableClass());
public static Boolean equals(Object obj1, Object obj2)
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.
public static System.ApplicationReadWriteMode getApplicationReadWriteMode()
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.
public class myClass { public static void execute() { ApplicationReadWriteMode mode = System.getApplicationReadWriteMode(); if (mode == ApplicationReadWriteMode.READ_ONLY) { // Do nothing. If DML operaton is attempted in readonly mode, // InvalidReadOnlyUserDmlException will be thrown. } else if (mode == ApplicationReadWriteMode.DEFAULT) { Account account = new Account(name = 'my account'); insert account; } } }
public static Integer hashCode(Object obj)
Type: Boolean
public static Boolean isBatch()
Type: Boolean
public static Boolean isFuture()
Type: Boolean
public static Boolean isScheduled()
Type: Boolean
public static Datetime now()
Type: Datetime
public static Integer purgeOldAsyncJobs(Date dt)
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.
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.
The requestVersion method isn’t supported for unmanaged packages. If you call it from an unmanaged package, an exception will be thrown.
public static System.ResetPasswordResult resetPassword(ID userId, Boolean sendUserEmail)
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.
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.
public static Void runAs(User userSObject)
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 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.
public static String schedule(String jobName, String cronExpression, Object schedulableClass)
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.
Seconds Minutes Hours Day_of_month Month Day_of_week optional_year
The following are the values for the expression:
Name | Values | Special Characters |
---|---|---|
Seconds | 0–59 | None |
Minutes | 0–59 | None |
Hours | 0–23 | , - * / |
Day_of_month | 1–31 | , - * ? / L W |
Month | 1–12 or the following:
|
, - * / |
Day_of_week | 1–7 or the following:
|
, - * ? / L # |
optional_year | null or 1970–2099 | , - * / |
Special Character | Description |
---|---|
, | 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. |
L | Specifies 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 28 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. |
W | Specifies 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#2 means the class runs on the second Monday of every month. |
The following are some examples of how to use the expression.
Expression | Description |
---|---|
0 0 13 * * ? | Class runs every day at 1 PM. |
0 0 22 ? * 6L | Class runs the last Friday of every month at 10 PM. |
0 0 10 ? * MON-FRI | Class runs Monday through Friday at 10 AM. |
0 0 20 * * ? 2010 | Class 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 13th of February.
proschedule p = new proschedule(); String sch = '0 0 8 13 2 ?'; system.schedule('One Time Pro', sch, p);
public static String scheduleBatch(Database.Batchable batchable, String jobName, Integer minutesFromNow)
For an example, see Using the System.scheduleBatch Method.
public static String scheduleBatch(Database.Batchable batchable, String jobName, Integer minutesFromNow, Integer scopeSize)
Type: String
For an example, see Using the System.scheduleBatch Method.
public static Void setPassword(ID userId, String password)
Type: Void
When the user logs in with this password, they are not prompted to create a new password. Use resetPassword(userId, sendUserEmail) if you want the user to go through the reset process and create their own password.
public static List<ID> submit(List<ID> workItemIds, String comments, String nextApprover)
For enhanced submit and evaluation features, see the ProcessSubmitRequest class.
public static Date today()
Type: Date