We are thinking of using External Services to integrate with an external application. Due to the nature of the application, we want to create logging records in Salesforce (creating a Log object to capture the message and response). Usually we store the request and response body in text areas on a log record so we have an exact account of what was sent and what was returned (for audit purposes).
External Services make use of Dynamic Apex Classes. These classes are fully managed within Flow - all the properties are set in Flow and the callout and callout result (including the response body) are available in the Flow runtime. However, there is no trivial way to serialize these classes and store them as a string in the request body fields on the log object - especially not in a way that is repeatable for different Dynamic Apex types. There is no JSON.serialize(requestBodyObject) or requestBodyObject.toString(), nor can an untyped Object be used as an InvocableVariable, it must have some type to pass it to Apex. We've tried the below, but this generates an error when deploying.
public class Input {
InvocableVariable(Label='Request Object' Description='The External Service object that is sent' Required=true)
public Object requestObject;
InvocableVariable(Label='Response Object' Description='The result object of the External Service' Required=true)
public Object responseObject;
}
Error: InvocableVariable fields do not support type of Object
Alternatively we've tried wrapping the requestObject and responseObject in an Apex Defined Data Type, however any properties with type Object will not show up in Flow Assignments and cannot be used. We are also aware that we can create a text-template with the JSON structure and fill that with the data for each single callout, but that is hardly repeatable or maintainable.
So the question is whether there is a reusable way to stringify objects in Flow, or pass generic objects/ Dynamic Apex objects to Apex for the above use case. Any help is greatly appreciated.