Friday, December 21, 2018

@RemoteAction Static methods with Inheritance, Composition & Polymorphism



This blog post is specifically highlighting an issue of @RemoteAction Static methods with Inheritance, Composition and Polymorphism.

You may read Inheritance, Composition over Inheritance and Polymorphism.


Hypothetical Scenario:

Universal Digital (UD) is a global internet, web, and domain hosting service provider organisation. They are planning to move their current solution on the Cloud. After analysing various software’s, they have chosen Salesforce. It will be a completely custom solution on Lightning platform. Initially two (2) regions: EMEA and NA will be going live in MVP phase.

The solution would be fully custom, the CTO of UD has given some benchmarks for the development. The most important one is that the code should be divided into two (2) parts:
  • Global Repository
    • It will have ONLY common code that will be same across Regions (EMEA, NA).
  • Regional Repository
    • Every Region (EMEA, NA) will have its own code repository where it will have Region specific code + Global common code.

Problem:

Development team is having issues specifically for @RemoteAction methods as developers are using heavily custom framework to build custom smart UI. So, Development team is struggling to find a way that how to use RemoteAction Static methods with Inheritance, Composition & Polymorphism?

Considerations of "Virtual", "Override" and "Static" Keywords in Apex

  • RemoteAction methods must be declared as "Static".
  • You can't use "Virtual" and "Override" keywords with "Static" keyword.

So specifically for @RemoteAction methods Development team needs to take a slightly different approach.



Please see an example of Remote Action Methods and Inheritance in detail by Salesforce.

Solution:

(1) How to Re-Use a Common base class @RemoteAction Static method for a Region (EMEA, NA)




(2) How to Extend a Common base class @RemoteAction method for a Region (EMEA, NA)

Approach 1


In this approach you are limited in Common base class and you can't Override any of the Common method in Region specific classes.



Approach 2

In this approach you have flexibility. You can Extend and Override the methods of Common class in a Region specific classes.