New Classes and Methods
These Apex classes have been added.
•
Cases
• TimeZone
Also, new UserInfo methods have been added.
Cases Class
Usage
Use the Cases class to interact with case records.
Cases class Methods
Method Name:
getCaseIdFromEmailThreadId()
Description:Returns the case ID corresponding to the specified email thread ID.The emailThreadId argument should have the following format:
_00Dxx1gEW._500xxYktg.
getCaseIdFromEmailThreadId String emailThreadId ID
Other formats, such as
ref:_00Dxx1gEW._500xxYktl:ref and
[ref:_00Dxx1gEW._500xxYktl:ref],
are invalid.
Cases Example
The following example uses an email thread ID to retrieve the related case ID.
public class GetCaseIdController {
public static void getCaseIdSample() {
// Get email thread ID
104
Force.com Apex Code
String emailThreadId = '_00Dxx1gEW._500xxYktg';
// Call Apex method to retrieve case ID from email thread ID
ID caseId = Cases.getCaseIdFromEmailThreadId(emailThreadId);
}
}
TimeZone Methods
Represents a time zone. Contains methods for creating a new time zone and obtaining time zone properties, such as the time
zone ID, offset, and display name.
Usage
You can use the methods in this class to get properties of a time zone, such as the properties of the time zone returned by
UserInfo.getTimeZone, or the time zone returned by getTimeZone of this class.
Methods
The following is the static method of the Timezone class.
getTimeZone()
Returns the time zone corresponding to the specified time zone ID.The time zone values you can use for the Id argument are any valid time zone values that the
Java TimeZone class supports. getTimeZone String Id TimeZone
Example:
TimeZone tz = TimeZone.getTimeZone('America/Los_Angeles');
System.assertEquals('Pacific Standard Time',tz.getDisplayName());
getDisplayName()
Returns this time zone’s display name.
getID()
Returns this time zone’s ID.
getOffset()
Returns the time zone offset, in milliseconds, of the specified date to the GMT time zone.The date argument is the date and time to evaluate.getOffset Datetime date Integer
Note: The returned offset is adjusted for daylight saving time if the date argument falls within daylight saving time for this
time zone.
toString()
Returns the string representation of this time zone
Sample
This example shows how to get properties of the current user’s time zone and displays them to the debug log.
TimeZone tz = UserInfo.getTimeZone();
System.debug('Display name: ' + tz.getDisplayName());
System.debug('ID: ' + tz.getID());
// During daylight saving time for the America/Los_Angeles time zone
System.debug('Offset: ' + tz.getOffset(DateTime.newInstance(2012,10,23,12,0,0)));
// Not during daylight saving time for the America/Los_Angeles time zone
System.debug('Offset: ' + tz.getOffset(DateTime.newInstance(2012,11,23,12,0,0)));
System.debug('String format: ' + tz.toString());
The output of this sample varies based on the user's time zone. This is an example output if the user’s time zone is
America/Los_Angeles. For this time zone, daylight saving time is -7 hours from GMT (-25200000 milliseconds) and standard
time is -8 hours from GMT (-28800000 milliseconds).
Display name: Pacific Standard Time
ID: America/Los_Angeles
Offset: -25200000
Offset: -28800000
String format: America/Los_Angeles
New UserInfo Methods
getTimeZone()
Returns the current user’s local time zone.
Example:
TimeZone tz =UserInfo.getTimeZone();
System.debug('Display name: ' +tz.getDisplayName());
System.debug('ID: ' +tz.getID());
getUserEmail()
Returns the current user’s email address.
Example:
String emailAddress =UserInfo.getUserEmail();
System.debug('Email address: ' +emailAddress);
Connect in Apex—Developer Preview
Note: Connect in Apex is currently available as a Developer Preview and is automatically available in all Developer
Edition organizations. For information on enabling Connect in Apex in other editions, contact Salesforce.
Connect in Apex exposes Chatter API data as Apex objects. Use classes in the ConnectApi namespace to develop Chatter
applications on the Force.com platform without using Apex callouts
The following documentation is available:
• To find out what’s new in Connect in Apex in Spring ‘13, see Connect in Apex—Developer Preview.
• The complete Connect in Apex documentation is available in the Chatter REST API Developer’s Guide from developerforce.com.
• Connect in Apex recipes are available in the Force.com Cookbook.
Triggers for CollaborationGroup and CollaborationGroupMember
Triggers are now available for CollaborationGroup and CollaborationGroupMember sObjects. You can create the
triggers by clicking Your Name > Setup > Customize > Chatter > Triggers, and then selecting CollaborationGroup Triggers or CollaborationGroupMember Triggers.
Note the following for the CollaborationGroup and CollaborationGroupMember objects:
• When CollaborationGroupMember is updated, CollaborationGroup is automatically updated as well to ensure that the member count is correct. As a result, when CollaborationGroupMember update or delete triggers run,
CollaborationGroup update triggers run as well.
• CollaborationGroup and CollaborationGroupMember objects can't be undeleted. Triggers marked only as after undelete will not be executed.
Setting Id Fields on sObjects for Updates
Starting with Apex code saved using Salesforce.com API version 27.0, the Id field is now writeable on sObject instances for all sObject types—standard objects, custom objects, and generic sObjects—for update operations. The insert operation doesn’t support setting Id fields on sObjects.
// Account a has some fields set
a.Phone = '(415) 555-1212';
// Also, set its Id field
a.Id = '00199000002JMim';
update a;
Previously, you couldn’t set the Id field after having created or obtained an sObject, such as an instance of Account. You could set the Id field only in the sObject’s constructor.
This change enables you to update existing records that correspond to sObject instances you already have, such as sObjects you obtained from deserializing JSON input. To do so, set the Id field on the sObjects to IDs of existing records in the database and call update. This call updates the corresponding records with all the other fields that are set on the sObjects.
This example shows that you can perform an update using any sObject reference of the same sObject type as long as you set the appropriate ID. First, this example creates two accounts, the second of which has an Industry field. Next, it updates the Industry field on the first account using the sObject reference of the second account (otherAcct) and sets the Id field on the sObject reference to the ID of the first account. It calls update and verifies that the Industry field has been set on the first account.
// Insert two accounts
Account acctToUpdate = new Account(Name='Account1');
insert acctToUpdate;
Account otherAcct = new Account(Name='Account2', Industry='Consulting');
insert otherAcct;
// Update the first account.
// The secondAcct sObject has the Industry field set.
// To update the first account with this same field, just set the ID
// to the first account on the sObject of the second account.
otherAcct.Id = acctToUpdate.Id;
update otherAcct;
// Verify the Industry is updated.
Account acctAfterUpdate = [SELECT Id,Name,Industry FROM Account WHERE Id=:acctToUpdate.Id];
System.assertEquals('Consulting', acctAfterUpdate.Industry);
Tests Started from the Apex Classes Page Run Asynchronously
When you run tests in the Apex Classes page by clicking Your Name > Setup > Develop > Apex Classes, and then either
clicking Run All Tests from the Apex Classes page or Run Test from a class page, the Apex tests now run asynchronously, and both the Developer Console and the Apex Test Execution page display your test results. Tests started through Run All Tests or Run Test no longer run synchronously.
Note that Apex tests that are run as part of a deployment, a package install, or a package upload, still run synchronously