You want to send an outbound message
to an external Web service when records are created or updated in Salesforce.com.
Set up a workflow rule to send
the outbound message, generate the WSDL document for the message,
and then set up a listener in your language of choice.
following example, we'll revisit our sample Recruiting application.
We'll set up a message to a legal services provider if a visa is required
before a candidate can start his or her new job:
- Click Setup | Create | Workflow & Approvals | Workflow
Rules and create a new workflow rule that
fires when a candidate is created, or when a candidate is edited and
did not previously meet the rule's criteria. Set the criteria for
the rule to be “Visa Required equals True.”
- Add an outbound message workflow action:
- In the Immediate Workflow Actions area, click Add Workflow Action | New Outbound
- Enter a name and description for the outbound message.
- Specify the Endpoint URL for the recipient
of the message. Salesforce.com sends
a SOAP message to this endpoint, which is the Web service listener
that will consume the outbound message.
- Select a Salesforce.com user
whose security settings will control the data that's visible for the
- Select Include Session ID if you want the Salesforce.comsessionId included in the message. You
should include it if you intend to make API calls
and you don't want to include a username and password in the body
of your message (which is far less secure than sending the sessionId).
- Select the field values that you want included in the outbound
- Click Save.
- Activate the workflow rule by returning to the Workflow Rule detail
page and clicking Activate.
- Generate the WSDL document for your outbound message: Return to
the Outbound Message detail page by clicking Setup | Create | Workflow
& Approvals | Outbound Messages and selecting the name of the outbound message. Then
click Click for WSDL. This file is bound to
the outbound message and contains the instructions about how to reach
the endpoint service and what data is sent to it. Save the file to
your local machine.
- Build a listener for the outbound message. This Web service endpoint
has to conform to the definition of the WSDL file. For example, to
build a listener using .NET:
- Run wsdl.exe/serverInterfaceleads.wsdl with
.NET 2.0. This generates NotificationServiceInterfaces.cs, which defines the notification interface.
- Create a class that implements NotificationServiceInterfaces.cs. While there are a number of ways to do this, one simple way
is to compile the interface to a .dll first (.dlls must be in the bin directory in ASP.NET):
mkdir bin csc /t:library /out:bin\nsi.dll NotificationServiceInterfaces.csThen write an ASMX-based Web service that implements this
interface. For example, a very simple implementation in MyNotificationListener.asmx might be:
class MyNotificationListener : INotificationBinding
notificationsResponse r =
r.Ack = true;
- Deploy the service by creating a new virtual directory in IIS
for the directory that contains MyNotificationListener.asmx.
You can test that the service is deployed by viewing the service
page with a browser. For example, if you create a virtual directory
named salesforce, navigate to http://localhost/salesforce/MyNotificationListener.asmx.
Although this recipe only outlines
the procedure for a .NET-based solution using IIS, the process for
other Web services-enabled languages and tools is similar. Note that
your listener must meet the following requirements:
- It must be reachable from the public Internet.
- If it uses SSL, it must use one of the following ports:
- 80: this port only accepts HTTP connections
- 443: this port only accepts HTTPS connections
- 7000-10000: these ports accept HTTP or HTTPS connections
- If it requires client certificates, you must have the current Salesforce.com client
certificate available at Setup | Develop | API.
- The common name (CN) of the listener's certificate must match
the domain name for your endpoint's server, and the certificate must
be issued by a Certificate Authority trusted by the Java 2 Platform,
Standard Edition 5.0 (JDK 1.5).