You are here:
Create a Trigger for the Base Object
The ReportCard trigger ensures that the Report_Card.EnableStateModel setting exists and is set to On, then invokes the processOnCreateActions method. You can rewrite it to work with a different base object.
To create a trigger for the Report_Card__c object:
- In Setup, click the Object Manager tab.
- In the Quick Find box, type report, then click Report Card.
- Click the Triggers tab, then click New.
- Remove all the code in the Apex Trigger tab.
- Paste the template code into the Apex Trigger tab at the cursor.
trigger ReportCard on Report_Card__c (after insert) { vlocity_ins__TriggerSetup__c myCS = vlocity_ins__TriggerSetup__c.getInstance('AllTriggers'); boolean isTriggerOn = false; List<Id> objIds; if(myCS!=null) { vlocity_ins__TriggerSetup__c objStateModelTrigger = vlocity_ins__TriggerSetup__c.getInstance('Report_Card.EnableStateModel'); boolean isObjStateModelEnabled = true; if (objStateModelTrigger != null) { isObjStateModelEnabled = objStateModelTrigger.vlocity_ins__IsTriggerOn__c; } system.debug('Is Report_Card.EnableStateModel enabled? ' + isObjStateModelEnabled); isTriggerOn = myCS.vlocity_ins__IsTriggerOn__c && isObjStateModelEnabled; system.debug('is trigger on? '+isTriggerOn); } else { system.debug('Cannot get Custom Setting for Report_Card.EnableStateModel trigger.'); } if(!Trigger.isBefore) { objIds = new List<Id>(); if(Trigger.isInsert) { for(SObject so : Trigger.new) { Report_Card__c newObj = (Report_Card__c) so; objIds.add(newObj.Id); } } } if(objIds != null && !objIds.isEmpty()) { Map<String, Object> output = new Map<String, Object>(); Map<String, Object> options = new Map<String, Object>(); ActionListService.processOnCreateActions(objIds, output, options); } } - Customize the template code:
-
Change
ReportCardto a trigger name that references a different base object name. -
Change all instances of
Report_Card__cto a different base object name. -
Change all instances of
Report_Card.EnableStateModelto a different trigger setting name.
If you are creating the Report Card example, leave the template code as is.
-
- Click Save.

