Tag Archives: Salesforce

Debugging Salesforce Callout

Inside of the Salesforce Apex class we can have a bit of code that execute an http request call to an external site, for example if we have a need to send information from Salesforce to an external site. Normally i would use Salesforce outbound message as it has more feature such as resend the message if the first request failed, able to send bulk messages and so on.

However Salesforce Outbound Message as part of the workflow can only be triggered on the create and update event of an entity. Therefore if we want to send information about the entity that is being manipulated on the delete event it’s not possible to do that.

The workaround is to use Apex Trigger that uses HttpRequest class to POST data to an external site, it could a be webservice and aspx page you get the idea. The downside is that there isn’t an easy way to see the debug log to see if the callout succeed or not when we execute the method because when we write a method that contain callout, that method has to be mark with @future(callout=true) and thus making it run asynchronously. Because of this all the log that we set inside the callout method will not showup on the developer console log viewer. Or is it..

Using the developer console, we can execute an Apex Code to trigger a callout, and then we can see the log just fine.



Make sure you tick the Open Log so that it opens the log viewer after executing the code


And then there’s the exception that i want to see.

a simple example of creating apex trigger and executing callout

checkout this link if you’re interested with viewing the http raw data when executing the callout

Salesforce Outbound Message Relay

In this post I’m gonna talk about how to relay the Salesforce outbound message to another environment. While trying to integrate Salesforce with another system, we usually use web service as method to communicate between the two. now the problem is that the outbound message can only send the message to publicly available servers.

This is not a good scenario because the publicly accessible servers is usually the production server, and doing development in production server is generally bad idea. A better approach would be if we have a message relayer that sits on the public server and then it forward any message to targeted environments, like for example the developer machine or our staging server.

Setting up the relayer

Before we go on, you should have some knowledge on the Salesforce Outbound Message itself, if not you really should read about it at http://www.salesforce.com/us/developer/docs/api/index_Left.htm#CSHID=sforce_api_om_outboundmessaging_setting_up.htm|StartTopic=Content%2Fsforce_api_om_outboundmessaging_setting_up.htm|SkinName=webhelp.

Done reading that ?. cool, let’s move on

Below we got a simple example of Outbound Message Listener

It’s not really doing much at the moment, so let’s changed that

You might wonder where “account-dev” is coming from, it’s actually the endpoint name that i setup on my web.config that points to one of the dev machine. So it basically boils down to this steps

  1. Pass the endpoint to the generated NotificationBindingClient
  2. Copy the value that we want to pass in
  3. Return the response so the Salesforce outbound message doesn’t get timeout or bad response

Of course this post doesn’t talk about handling duplicate message in the outbound messages, and or how to build a queuing system to handle the outbound messages when under heavy load. There’s a good post already that you can find at http://www.nimbleuser.com/_Blogs/Developers/Developers/Unloading_Salesforce_CRM_Data_with_Outbound_Messages.aspx