Skip to content

Create a Trigger

PhoneTools needs a trigger on each object it screens. The trigger does one job: when a phone number on a record changes, it resets that record's functional fields so the record is queued for screening again. The Phone Status Field goes back to Not Screened, and the Next Screen Due Field and Screening Results Field are emptied.

What Is Supplied out of the Box

The package includes a trigger for each of the three supported objects:

Object Trigger name
Account ProcessPhoneNumberUpdate_Account
Contact ProcessPhoneNumberUpdate_Contact
Lead ProcessPhoneNumberUpdate_Lead

If you are only screening phone fields on Account, Contact or Lead, there is nothing to do here, and you can move on to configuring your fields.

If you plan to screen a phone field on any other standard or custom object, read on.

Creating a Trigger for Another Object

  1. Go to Setup.
  2. Open Object Manager.
  3. Locate the object you want to screen and open it.
  4. Select Triggers, then New.
  5. Replace the contents of the editor with the snippet below:

    trigger ProcessPhoneNumberUpdate_OBJECTLABEL on OBJECTAPI (before update) {
        pw_pss.PhoneNumberUpdateHelper.ProcessUpdate('OBJECTAPI', Trigger.oldMap, Trigger.newMap);
    }
    
  6. Replace OBJECTLABEL with the label of the object you are screening, so that the trigger has a recognisable name.

  7. Replace both occurrences of OBJECTAPI with the API name of that object, for example Invoice__c. The value passed as the first argument must be the object's API name, because PhoneTools uses it to look up the configuration for that object.
  8. Select Save.

Note: Apex cannot be created directly in a production org. Create and test the trigger in a sandbox or Developer Edition org, then deploy it to production along with an Apex test class. A simple test that inserts and then updates a record on the object is enough to cover the trigger.

Good to Know

  • The trigger must run before update. It changes field values on the records being saved, and does not perform any DML of its own.
  • pw_pss.PhoneNumberUpdateHelper.ProcessUpdate only acts on phone fields that are configured in PhoneTools and also have Enable Screening ticked, so adding the trigger on its own has no effect until you configure a field to screen.
  • The three functional fields must exist on the object and be selected in the configuration before the trigger can reset anything. See Create the Functional Fields.
  • The Phone Screen Settings Custom Setting includes Disable Account Trigger, Disable Contact Trigger and Disable Lead Trigger, which switch off the packaged triggers. Because Phone Screen Settings is a hierarchy Custom Setting, each switch is evaluated for the user running the save, so it can be set for the whole organisation or for one profile or user. These switches do not apply to a trigger you write yourself, so build in your own control if you need one.