[SalesForce] Http callout from Apex

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.

Best Answer

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.

Related Topic