3

I want to send a http callout to a external system we are intergrating with.

How do I go about setting up this class so that when a user updates any record, this message is sent out to the external system: "http://{Salesforce}/{RecordId}/{UserId}/{Action}" where {salesforce} is hardcoded and {Action} is a dml action like update, delete etc.

I am hoping this will be a class that accepts parameters since this needs to be fired whenever a dml action has been done from a number of objects.

Also, I am assuming the method has to be POST.

2 Answers 2

3

This will require triggers and @future methods.

  1. For every object that you want to apply this to, you will need to create a trigger that covers the desired events (before/after, insert/update/delete, etc. . .). In other words this will require one trigger per object; there is no way to have a generic trigger.
  2. Create a helper method marked @future(callout=true) that accepts the necessary parameters. This method will make the actual callouts.
  3. Have your triggers call the helper method, when applicable.

Something to note:

You will likely run into governor limits. A transaction can only make 10 callouts so bulkifying this will be hard unless you can concatenate all of the updates into the body of one message. You could also circumvent this by only making the callout on single record transactions.

5
  • Thanks a lot Mike for your quick response. Might you have a sample trigger and helper class that I can look at to guide me through. Do you mind expounding on the 10 callouts on update? Isn't one update equal to 1 callout or am I mistaken?
    – Kenn K
    Commented Dec 2, 2013 at 20:52
  • If you had a bulk update of records the trigger would fire once for all of them (up to 200 per trigger.) That's when you'd have to be careful and decide how to handle them. Here's an example trigger with callout - cheenath.com/?tutorial/sfdc/sample1/index.html
    – Mike Chale
    Commented Dec 2, 2013 at 20:57
  • Thanks a lot Mike.. let me give it a shot! I really appreciate your help.
    – Kenn K
    Commented Dec 2, 2013 at 21:24
  • Quick question, don't you think the setMethod should be 'POST' though? I don't really care about the response for the external system and from the example, I think it waits for the response.
    – Kenn K
    Commented Dec 2, 2013 at 21:33
  • That depends on your web service. All of them will wait for a response, though; whether it's a SOAP or REST service, or if the verb is GET or POST. Your service could just return a quick response to end the callout quickly, though. Given the task, I would expect the verb to be POST, though.
    – Mike Chale
    Commented Dec 2, 2013 at 21:35
1

I would create a HTTP proxy on another public accessible server that can take many requests in one. Like a Json string in the post body with all the requests. Then the proxy goes through all the requests and sends a response to a web service method in SF. The response can be a Json string with all the responses. I know it requires a day work or two, but totally Worth it. One should of course use SSL.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .