Getting started with Config.apex
Config Handlers
After creating the instance of the config service, we need to correctly set it up for use. A config service is a facade that accepts config requests on certain config urls, process the requests and send back the responses. It dispatches the config requests to config handlers to process.
onfigService.onRead('/System/version', new SystemVersionFunc());
Here we registered a config handler SystemVersionFunc
to process requests from config url /System/version
. Also we can register config handlers to process requests to update configuration values.
configService.onWrite('/System/version', new SystemVersionWriteFunc());
By default, config handlers work on the org cache. But we can specify them to work on the session cache too.
configService.onRead('/System/version', true, Config.SCOPE_SESSION, new SystemVersionFunc());
Or even we can turn off the cache used by the config handlers, when sometimes we need to always get the update-to-date data.
configService.onRead('/System/version', false, new SystemVersionFunc());
In case of complicated config requests, we also support parameterized url matching.
public class CustomHandler extends Func {
public override Object exec(Object arg) {
Map params = (Map)arg;
String version = params.get('version');
// Custom logic
return 'config value';
}
public override Object exec(Object arg1, Object arg2) {
Map params = (Map)arg1;
Map data = (Map)arg2;
// Custom logic
return null;
}
}
Func handler = new CustomHandler();
configService.onReadWrite('/System/version/${version}', handler, handler);