Portal Communication Architecture

From 3B Knowledge
Jump to navigation Jump to search

Intro

When creating custom portal components, you may need to call custom apex classes. To do so, starting version 1.23 of the 3B Portals app, you simply need to implement the System.Callable class.

Classes that need to be called from the portal custom components no longer need to use the b3p.GlobalRemotingInterface interface, instead they should rely solely on the system class "System.Callable"

//Old Format
public with sharing class CustomClass implements b3p.GlobalRemotingInterface{
    ...
}
//New Format
public with sharing class CustomClass implements System.Callable {
    ...
}

Then, simply implement a call method like so:

public static Object call(String action, Map<String, Object> args) {
        switch on action {
            when 'someAction' {
                return upsertRecords(
                    (String) args.get('param1'), 
                    (String) args.get('param2'));
            }
            when else {
                return new ErrorResponse(
                    String.format(
                        'Invalid Paraeter for class {0} and action {1}',
                        new List<Object>{ 'This class', action }
                    )
                );
            }
        }
    }