The following are the static methods for System.
| Name | Arguments | Return Type | Description |
|---|---|---|---|
| abortJob | String Job_ID | Void | Stops the specified job. The stopped job is still visible in
the job queue in the Salesforce user interface. The Job_ID is the ID associated
with either AsyncApexJob or CronTrigger. One of
these IDs is returned by the following methods:
|
| assert | Boolean condition, Any data type opt_msg |
Void | Asserts that condition is true. If it is not, a runtime exception is thrown with the optional second argument, opt_msg, as part of its message. |
| assertEquals | Any data type x, Any data type y, Any data type opt_msg |
Void | Asserts that the first two arguments, x and y, are the same. If they are not, a runtime exception is thrown with the optional third argument, opt_msg, as part of its message. |
| assertNotEquals | Any data type x, Any data type y, Any data type opt_msg |
Void | Asserts that the first two arguments, x and y are different. If they are the same, a runtime exception is thrown with the optional third argument, opt_msg, as part of its message. |
| currentPageReference | System.PageReference | Returns a reference to the current page. This is used with Visualforce pages. For more information, see PageReference Class. | |
| currentTimeMillis | Long | Returns the current time in milliseconds, which is expressed as the difference between the current time and midnight, January 1, 1970 UTC. | |
| debug | Any data type msg | Void | Writes the argument msg, in string format,
to the execution debug log. If you do not specify a log level, the DEBUG log level is used. This means
that any debug method with
no log level specified, or a log level of ERROR, WARN, INFO or DEBUG is 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
(()). For more information on log levels, see “Setting Debug Log Filters” in the Salesforce online help. |
| debug | Enum logLevel Any data type msg |
Void | Specifies the log level for all debug methods. Log levels are cumulative. For example, if the lowest level, ERROR, is specified, 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.debug
(Logginglevel.ERROR);
System.debug(Logginglevel.INFO,
'MsgTxt');For more information on log levels, see “Setting Debug Log Filters” in the Salesforce online help. |
| getApplication ReadWriteMode | System.ApplicationReadWriteMode | Returns the read write mode set for an organization during
Salesforce.com upgrades and downtimes. This method returns the enum
System.ApplicationReadWriteMode. Valid values are:
|
|
| isBatch | Boolean | Returns true if the
currently executing code is invoked by a batch Apex job; false otherwise. Since a future method can't be invoked from a batch Apex job, use this method to check if the currently executing code is a batch Apex job before you invoke a future method. |
|
| isFuture | Boolean | Returns true if the
currently executing code is invoked by code contained in a method
annotated with future; false otherwise. 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. |
|
| isScheduled | Boolean | Returns true if the currently executing code is invoked by a scheduled Apex job; false otherwise. | |
| now | Datetime | Returns the current date and time in the GMT time zone. | |
| process | List<WorkItemIDs> WorkItemIDs String Action String Comments String NextApprover |
List<Id> | Processes the list of work item IDs. For more information, see Apex Approval Processing Classes. |
| requestVersion | System.Version | Returns a two-part version that
contains the major and minor version numbers of a package.
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. |
|
| resetPassword | ID userID Boolean send_user_email |
System.ResetPasswordResult | Resets the password for the specified user. 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 send_user_email, 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 if you don't want the user to be prompted to enter a new password when they log in. |
| runAs | Package.Version version | Void | Changes the current package version
to the package version specified in the argument.
A package developer can use package 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 Apex 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 the Package.Version.Request object 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. |
| runAs | System.Version version | Void | Changes the current package version
to the package version specified in the argument.
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 Apex 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. |
| runAs | User user_var | Void | Changes the current user to the specified user. All of the specified user's permissions and record sharing are enforced during the execution of runAs. You can only use runAs in a test method. For more information, see Using the runAs Method. |
| schedule | String JobName String CronExpression Object schedulable_class |
String | Use schedule with an Apex class that implements the Schedulable interface to schedule the class to run at the time specified by CronExpression. Use extreme care if you are planning to schedule a class from a trigger. You must be able to guarantee that the trigger will not add more scheduled classes than the 25 that are allowed. 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.For more information see, Using the System.Schedule Method. Use the abortJob method to stop the job after it has been scheduled. |
| setPassword | ID userID String password |
Void | Sets the password for the specified user. When the user logs in with this password, they are not prompted to create a new password. Use resetPassword if you want the user to go through the reset process and create their own password. |
| submit | List<WorkItemIDs> WorkItemIDs String Comments String NextApprover |
List<ID> | Submits the processed approvals. For more information, see Apex Approval Processing Classes. |
| today | Date | Returns the current date in the current user's time zone. |
Use the loggingLevel enum to specify the logging level for all debug methods.
Log levels are cumulative. For example, if the lowest level, ERROR, is specified, 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 “Setting Debug Log Filters” in the Salesforce online help.
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; } } }
SecondsMinutesHoursDay_of_monthMonthDay_of_weekoptional_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);
A System.ResetPasswordResult object is returned by the System.ResetPassword method. This can be used to access the generated password.
The following is the instance method for the System.ResetPasswordResult object:
| Method | Arguments | Returns | Description |
|---|---|---|---|
| getPassword | String | Returns the password generated as a result of the System.ResetPassword method that instantiated this System.ResetPasswordResult object. |