Professional Documents
Culture Documents
SFDC 001
SFDC 001
SFDC 001
Enum Description
• Started
See Also:
Chatter in Apex Classes
ConnectApi Exceptions
The ConnectApi namespace contains exception classes.
All exceptions support built-in methods for returning the error message and exception type. The ConnectApi namespace
contains these exceptions:
Exception Description
ConnectApi.ConnectApiException Any logic error in the way your application is utilizing
ConnectApi code. This is equivalent to receiving a 400 error
with Chatter API in REST.
ConnectApi.NotFoundException Any issues with the specified resource being found. This is
equivalent to receiving a 404 error with Chatter API in REST.
ConnectApi.RateLimitException When you exceed the rate limit. This is equivalent to receiving
a 503 Service Unavailable error with Chatter API in REST.
See Also:
Chatter in Apex Classes
Exception Class
You can create your own exception classes in Apex. Exceptions can be top-level classes, that is, they can have member variables,
methods and constructors, they can implement interfaces, and so on.
Exceptions that you create behave as any other standard exception type, and can be thrown and caught as expected.
User-defined exception class names must end with the string exception, such as “MyException”, “PurchaseException” and
so on. All exception classes automatically extend the system-defined base class exception.
For example, the following code defines an exception type within an anonymous block:
try {
Integer i;
// Your code here
if (i < 5) throw new MyException();
} catch (MyException e) {
612
Reference Apex Classes
Like Java classes, user-defined exception types can form an inheritance tree, and catch blocks can catch any portion. For
example:
try {
Integer i;
// Your code here
if (i < 5) throw new OtherException('This is bad');
} catch (BaseException e) {
// This catches the OtherException
}
• Constructing an Exception
• Using Exception Variables
Constructing an Exception
You can construct exceptions:
• With no arguments:
new MyException();
• With a single Exception argument that specifies the cause and that displays in any stack trace:
new MyException(e);
• With both a String error message and a chained exception cause that displays in any stack trace:
For example the following code generates a stack trace with information about both My1Exception and My2Exception:
613
Reference Flow.Interview Class
The following figure shows the stack trace that results from running the code above:
Exception e1;
try {
String s = null;
s.tolowercase(); // This will generate a null pointer exception...
} catch (System.NullPointerException e) {
e1 = e; // ...which can be assigned to a variable, or passed
// into or out of another method
}
Flow.Interview Class
The Flow.Interview class provides advanced Visualforce controller access to flows.
Usage
Used with Visual Workflow, the Flow.Interview class has one method, which enables a Visualforce controller to access
the value of a flow variable embedded in the Visualforce page, or in a separate flow called by a subflow element.
Methods
The following is the instance method of the Flow.Interview class.
614
Reference HTTP (RESTful) Services Classes
Sample
The following sample uses the getVariableValue method to obtain breadcrumb (navigation) information from the flow
embedded in the Visualforce page. If that flow contains subflow elements, and each of the referenced flows also contains a
vaBreadCrumb variable, the Visualforce page can provide users with breadcrumbs regardless of which flow the interview is
running.
}
}
• HTTP Classes
• Crypto Class
• EncodingUtil Class
HTTP Classes
These classes expose the general HTTP request/response functionality:
• Http Class. Use this class to initiate an HTTP request and response.
• HttpRequest Class: Use this class to programmatically create HTTP requests like GET, POST, PUT, and DELETE.
• HttpResponse Class: Use this class to handle the HTTP response returned by HTTP.
615
Reference Apex Classes
• HttpRequest:
◊ HTTP request types such as GET, POST, PUT, DELETE, TRACE, CONNECT, HEAD, and OPTIONS.
◊ Request headers if needed.
◊ Read and connection timeouts.
◊ Redirects if needed.
◊ Content of the message body.
• HttpResponse:
The following example shows an HTTP GET request made to the external server specified by the value of url that gets
passed into the getContent method. This example also shows accessing the body of the returned response:
// Instantiate a new HTTP request, specify the method (GET) as well as the endpoint
HttpRequest req = new HttpRequest();
req.setEndpoint(url);
req.setMethod('GET');
The previous example runs synchronously, meaning no further processing happens until the external Web service returns a
response. Alternatively, you can use the @future annotation to make the callout run asynchronously.
Before you can access external servers from an endpoint or redirect endpoint using Apex or any other feature, you must add
the remote site to a list of authorized remote sites in the Salesforce user interface. To do this, log in to Salesforce and from
Setup, click Security Controls > Remote Site Settings.
Note: The AJAX proxy handles redirects and authentication challenges (401/407 responses) automatically. For more
information about the AJAX proxy, see AJAX Toolkit documentation.
Use the DOM Classes or JSON Classes to parse XML or JSON content in the body of a request created by HttpRequest,
or a response accessed by HttpResponse.
Http Class
Use the Http class to initiate an HTTP request and response. The Http class contains the following public methods:
616