Download Salesforce.com Winter `13 Release Notes

Transcript
Developer Console Enhancements
Apex Code Enhancements
a String representation of the argument. Previously, System.debug and String.valueOf always wrote or returned the
argument’s String representation and didn’t call toString, even when available on the argument object.
This example illustrates the new behavior of System.debug. It calls String.valueOf and System.debug on a type,
which invokes the Type toString method.
Type t = List<Integer>.class;
// Converts to String using the Type.toString method
String s = String.valueOf(t);
// Returns: LIST<Integer>
// It used to return: Type:[aot=LIST<Integer>]
System.assertEquals('LIST<Integer>', s);
// System.debug use the Type.toString method
// to convert the type to a string.
// Writes LIST<Integer> to the debug output
System.debug(t);
This example shows how the overridden toString method of a user-defined class gets invoked by String.valueOf and
System.debug. The class with the overridden toString method is listed first, followed by a code snippet that calls
String.valueOf and System.debug.
public class PairNumbers {
Integer x,y;
public PairNumbers(Integer a, Integer b) {
x=a;
y=b;
}
public override String toString() {
return '(' + x + ',' + y + ')';
}
}
PairNumbers p = new PairNumbers(1,2);
// Converts to String using the Type.toString method
String s = String.valueOf(p);
// Returns: (1,2)
// It used to return: PairNumbers:[x=1, y=2]
System.assertEquals('(1,2)', s);
// System.debug use the Type.toString method
// to convert the type to a string.
// Writes (1,2) to the debug output
System.debug(p);
SOQL Polymorphism Available in Apex—Developer Preview
You can use SOQL Polymorphism in your SOQL queries in Apex. This is typically done using the new TYPEOF clause. For
more details about SOQL Polymorphism, see SOQL Polymorphism—Developer Preview on page 163.
184