Close Sun Nov 18 14:57:24 GMT 2018

Callable in API 44.0

All developers glue Apex code together from different sources. But it's also a developer's job to worry about dependencies.

When we needed a way to implement loosely coupled integrations, Andrew Fawcett floated a possible solution:

callable-example

The delivery of Callable in API 44.0 finally allows developers to address the "ripple effect" where modifying one class causes many downstream changes.

Streams uses the Callable interface so that developers and consultants from different companies can create services that communicate across namespaces.

abstract public class Service implements Callable
{
  abstract List<Map<String,Object>> execute(Object event);

  public Object call(String method, Map<String,Object> arguments)
  {
    if (method == 'execute') {
      Map<String,Object> event = (Map<String,Object>)arguments.get('event');
      List<Map<String,Object>> events = this.execute(event);
      return events;
    }
    throw new StringException('Method not implemented: ' + method);
  }
}

Although Type.forName always supported casting to interfaces, somebody always had to be the master of a custom interface. Now it's part of the platform.



Related