Skip to content

Instantly share code, notes, and snippets.

@Damecek
Created August 28, 2025 12:20
Show Gist options
  • Select an option

  • Save Damecek/8b76cc18ecea4d4d8ae83bc69fa9c19c to your computer and use it in GitHub Desktop.

Select an option

Save Damecek/8b76cc18ecea4d4d8ae83bc69fa9c19c to your computer and use it in GitHub Desktop.
Chainable framework apex
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