Recipes by Category

App Distribution (2) Bundle logic, interface and services for distribution. App Logic (37) The Apex programming language, workflow and formulas for logic. Collaboration (5) The Salesforce Chatter collaboration platform. Database (29) Data persistence, reporting and analytics. Integration (33) Web Service APIs and toolkits for integration. Security (9) Platform, application and data security. Tools (4) Force.com tooling User Interface (36) Visualforce MVC and metadata-drive user interfaces. Web Sites (12) Public web sites and apps with optional user registration and login.
Beta Feedback
Cookbook Home » Sending Outbound Messages with Workflow

Sending Outbound Messages with Workflow

Post by Developer Force  (2010-07-16)

Status: Certified
Level: novice

Problem

You want to send an outbound message to an external Web service when records are created or updated in Salesforce.com.

Solution

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.

For the 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:
  1. 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.”
  2. Add an outbound message workflow action:
    1. In the Immediate Workflow Actions area, click Add Workflow Action | New Outbound Message.
    2. Enter a name and description for the outbound message.
    3. 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.
    4. Select a Salesforce.com user whose security settings will control the data that's visible for the message.
    5. 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).
    6. Select the field values that you want included in the outbound message.
    7. Click Save.
  3. Activate the workflow rule by returning to the Workflow Rule detail page and clicking Activate.
  4. 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.
  5. 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:
    1. Run wsdl.exe/serverInterfaceleads.wsdl with .NET 2.0. This generates NotificationServiceInterfaces.cs, which defines the notification interface.
    2. 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.cs
      Then write an ASMX-based Web service that implements this interface. For example, a very simple implementation in MyNotificationListener.asmx might be:
      <%@WebService class="MyNotificationListener" 
                    language="C#"%>
      class MyNotificationListener : INotificationBinding
      {	
          public notificationsResponse 
                  notifications(notifications n)
          {
      	       notificationsResponse r = 
                      new notificationsResponse();
              r.Ack = true;
              return r;
          }
      }  
    3. 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.

Discussion

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).

Share

Recipe Activity - Please Log in to write a comment

ok

voted as verified by sailappa nayagam  (2013-09-04)

This is great for .Net 2.0, but from what I have read elsewhere, this is a deprecated method. Could someone please share the VS2010 .Net 4.0 solution? Thanks.

by Colin McClure  (2011-04-09)

X

Vote to Verify a Recipe

Verifying a recipe is a way to give feedback to others and broaden your own understanding of the capabilities on Force.com. When you verify a recipe, please make sure the code runs, and the functionality solves the articulated problem as expected.

Please make sure:
  • All the necessary pieces are mentioned
  • You have tested the recipe in practice
  • Have sent any suggestions for improvements to the author

Please Log in to verify a recipe

You have voted to verify this recipe.