Created
August 28, 2025 12:20
-
-
Save Damecek/8b76cc18ecea4d4d8ae83bc69fa9c19c to your computer and use it in GitHub Desktop.
Chainable framework apex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public abstract class Chainable implements Queueable { | |
| private Chainable next; | |
| private ChainableContext context; | |
| public Chainable() { | |
| this.context = new BaseContext(); | |
| } | |
| protected abstract void execute(ChainableContext context); | |
| public Chainable enqueue(Chainable next) { | |
| if (this.next == null) { | |
| this.next = next; | |
| } else { | |
| this.next.enqueue(next); | |
| } | |
| return this; | |
| } | |
| protected void setContext(ChainableContext context) { | |
| this.context = context; | |
| } | |
| public void execute(QueueableContext context) { | |
| execute(this.context); | |
| if (next != null) { | |
| next.setContext(this.context); | |
| System.enqueueJob(next); | |
| } | |
| } | |
| public interface ChainableContext { | |
| Object getContext(); | |
| } | |
| public class BaseContext implements ChainableContext { | |
| public Object getContext() { | |
| return null; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment