SFDC 001
SFDC 001
Methods
The following are static methods of the System.Type class.
forName String namespace System.Type Returns the type that corresponds to the specified
namespace and class name.
String name
The namespace argument is the namespace of
the class.
The name argument is the name of the class.
If the class doesn't have a namespace, set the
namespace argument to null or an empty string.
Type myType =
Type.forName('MyNamespace',
'ClassName');
487
Reference Apex Standard Classes and Methods
Type t1 = Account.class;
Type t2 = Type.forName('Account');
System.assert(t1.equals(t2));
Type t =
Type.forName('MyClassName');
String typeName =
t.getName();
System.assertEquals('MyClassName',
typeName);
hashCode Integer Returns a hash code value for the current type.
The returned hash code value corresponds to the
type name hash code that String.hashCode
returns.
488
Reference Apex Standard Classes and Methods
Type t =
Type.forName('ShapeImpl');
Shape newObj =
(Shape)t.newInstance();
Type t =
List<Integer>.class;
String s = t.toString();
System.assertEquals(
'LIST<Integer>', s);
The method in this class gets the name of the class that implements the Vehicle interface through a custom setting value.
It then instantiates this class by getting the corresponding type and calling the newInstance method. Next, it invokes the
489
Reference Apex Standard Classes and Methods
methods implemented in VehicleImpl. This sample requires that you create a public list custom setting named
CustomImplementation with a text field named className. Create one record for this custom setting with a data set
name of Vehicle and a class name value of VehicleImpl.
Class Property
The class property returns the System.Type of the type it is called on. It is exposed on all Apex built-in types including
primitive data types and collections, sObject types, and user-defined classes. This property can be used instead of forName
methods.
Call this property on the type name. For example:
System.Type t = Integer.class;
You can use this property for the second argument of JSON.deserialize, deserializeStrict,
JSONParser.readValueAs, and readValueAsStrict methods to get the type of the object to deserialize. For example:
URL Methods
Represents a uniform resource locator (URL) and provides access to parts of the URL. Enables access to the Salesforce instance
URL.
Usage
Use the methods of the System.URL class to create links to objects in your organization. Such objects can be files, images,
logos, or records that you want to include in external emails, in activities, or in Chatter posts. For example, you can create a
link to a file uploaded as an attachment to a Chatter post by concatenating the Salesforce base URL with the file ID, as shown
in the following example:
490
Reference Apex Standard Classes and Methods
'/' + doc.id;
system.debug(fullFileURL);
The following example creates a link to a Salesforce record. The full URL is created by concatenating the Salesforce base URL
with the record ID.
Account acct = [SELECT Id FROM Account WHERE Name = 'Acme' LIMIT 1];
String fullRecordURL = URL.getSalesforceBaseUrl().toExternalForm() + '/' + acct.Id;
Constructors
Arguments Description
String protocol Creates a new instance of the System.URL class using the specified
protocol, host, port, and file on the host.
String host
Integer port
String file
String protocol Creates a new instance of the System.URL class using the specified
protocol, host, and file on the host. The default port for the specified
String host
protocol is used.
String file
URL context Creates a new instance of the System.URL class by parsing the specified
spec within the specified context.
String spec
For more information about the arguments of this constructor, see the
corresponding URL(java.net.URL, java.lang.String) constructor for Java.
String spec Creates a new instance of the System.URL class using the specified string
representation of the URL.
Methods
The following are static methods for the System.URL class.
getFileFieldURL String entityId String Returns the download URL for a file
attachment.
String fieldName
The entityId argument specifies the ID
of the entity that holds the file data.
The fieldName argument specifies the API
name of a file field component, such as
AttachmentBody.
491