Skip to content

Commit ac1e38c

Browse files
authored
Update README.md example of Apex plugin (#782)
1 parent 2445dcb commit ac1e38c

1 file changed

Lines changed: 23 additions & 20 deletions

File tree

README.md

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -798,26 +798,29 @@ If you want to add your own automation to the `Log__c` or `LogEntry__c` objects,
798798
3. `Output` parameter `updatedTriggerNew` - If your Flow makes any updates to the collection of records, you should return a record collection containing the updated records
799799
4. `Input` parameter `triggerOld` - The list of logger records as they exist in the datatabase
800800

801-
- Apex plugins: your Apex class should extend the abstract class `LoggerSObjectHandlerPlugin`. For example:
802-
803-
```apex public class ExamplePlugin extends LoggerSObjectHandlerPlugin {
804-
public override void execute(
805-
TriggerOperation triggerOperationType,
806-
List<SObject> triggerNew,
807-
Map<Id, SObject> triggerNewMap,
808-
List<SObject> triggerOld,
809-
Map<Id, SObject> triggerOldMap
810-
) {
811-
switch on triggerOperationType {
812-
when BEFORE_INSERT {
813-
for (Log__c log : (List<Log__c>) triggerNew) {
814-
log.Status__c = 'On Hold';
815-
}
816-
}
817-
}
818-
}
819-
}
820-
801+
- Apex plugins: your Apex class should implements `LoggerPlugin.Triggerable`. For example:
802+
803+
```apex
804+
public class ExampleTriggerablePlugin implements LoggerPlugin.Triggerable {
805+
public void execute(LoggerPlugin__mdt configuration, LoggerTriggerableContext input) {
806+
// Example: only run the plugin for Log__c records
807+
if (context.sobjectType != Schema.Log__c.SObjectType) {
808+
return;
809+
}
810+
811+
List<Log__c> logs = (List<Log__c>) input.triggerNew;
812+
switch on input.triggerOperationType {
813+
when BEFORE_INSERT {
814+
for (Log__c log : logs) {
815+
log.Status__c = 'On Hold';
816+
}
817+
}
818+
when BEFORE_UPDATE{
819+
// TODO add before-update logic
820+
}
821+
}
822+
}
823+
}
821824
```
822825

823826
Once you've created your Apex or Flow plugin(s), you will also need to configure the plugin:

0 commit comments

Comments
 (0)