Mini Postman with InvocableCallout Apex Action in Salesforce Flow

Hi folks, In this article I’d show you how I made a “mini Postman” with Salesforce Flow. And the good news is you can use this Apex Action in Flow to do your own callout, as an alternative of External Services (if you’re too lazy to create your own swagger schema, or you found External Services limitations in your use case).

If you’re interested in using this InvocableCallout Action beside the “mini Postman” use case, I highly suggest you to visit these two documentations on how I managed to parse JSON data with Salesforce Flow.

When to use InvocableCallout (and JSON utility above) instead of External Services?

  1. When you don’t have a swagger schema with External Services Spec
  2. When you have a complex JSON schema that cannot be handled by External Services
  3. When you want to convert your request body to blob type and want to compress your request body to gzip
  4. When you want to get the HTML data from a url
  5. When you want to catch response headers from your 3rd party app

Attributes

Input

  1. Method (mandatory)
    Data type: String / Text
    Note: Select one => (GET, POST, PATCH, PUT, DELETE, TRACE, CONNECT, HEAD, OPTIONS)
  2. Endpoint (mandatory)
    Data type: String / Text
    Note:
    Your 3rd part endpoint (e.g=> https://jsonplaceholder.typicode.com/posts/) or unique named credential. (e.g=> callout:jsonplaceholder/posts)
    Make sure you already register the endpoint to named credentials or Remote Site Setting
  3. Body
    Data type: String / Text
    Note: your request body, can be anything. JSON, XML, text, etc
  4. Timeout
    Data Type: Integer / Number
    Note: your request max timeout in Ms, default is 10,000 ms (or 10 seconds)
  5. Headers
    Data type: String / Text
    Note: your request headers in JSON format. follow format below
    [
    {“key”:”Content-Type”,”value”:”application/json”},{“key”:”Accept”,”value”:”*\*”}
    ]
  6. BodyAsBlob
    Data type: Boolean
    Note: if true, convert your request body to Blob Type
  7. Compressed_gzip
    Data type: Boolean
    Note: if true, compress your body request to gzip

Output

  1. Status
    Data type: String / Text
    Note: Status Response in text
  2. Status_code
    Data type: Integer / Number
    Note: Status Response in code
  3. Body
    Data type: String / Text
    Note: Response body
  4. CollectionOfHeaders
    Data type: String/Text in Collection variable
    Note: list of response headers in JSON format. combine with loop and MultipleJSONParser, if you need to parse the Headers. Format of JSON:
    {“key”:”Content-Type”,”value”:”application/json”}
  5. Error_Message
    Data type: String / Text
    Note: Error message when you trying to do callout

Installation:
(don’t forget to change login to test.login if you want to install in sandbox):
https://login.salesforce.com/packaging/installPackage.apexp?p0=04t2w000009F5mg

Source code: github

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store