Loading
Get Started with Communications, Media, and Energy & Utilities (CME)...
Table of Contents
Select Filters

          No results
          No results
          Here are some search tips

          Check the spelling of your keywords.
          Use more general search terms.
          Select fewer filters to broaden your search.

          Search all of Salesforce Help
          Create a Trigger for the Base Object

          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.

          Important
          Important

          The trigger code uses the namespace vlocity_ins for custom objects and fields. If your org has a different namespace, vlocity_cmt or vlocity_ps, use that instead.

          To create a trigger for the Report_Card__c object:

          1. In Setup, click the Object Manager tab.
          2. In the Quick Find box, type report, then click Report Card.
          3. Click the Triggers tab, then click New.
          4. Remove all the code in the Apex Trigger tab.
          5. 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);
                }
            }
          6. Customize the template code:
            • Change ReportCard to a trigger name that references a different base object name.

            • Change all instances of Report_Card__c to a different base object name.

            • Change all instances of Report_Card.EnableStateModel to a different trigger setting name.

            If you are creating the Report Card example, leave the template code as is.

          7. Click Save.
           
          Loading
          Salesforce Help | Article