--- title: "Example: Custom Trigger for EmailMessage" slug: "custom-trigger-for-emailmessage" updated: 2022-07-13T20:55:28Z published: 2022-07-13T20:55:27Z canonical: "docs.blackthorn.io/custom-trigger-for-emailmessage" --- > ## Documentation Index > Fetch the complete documentation index at: https://docs.blackthorn.io/llms.txt > Use this file to discover all available pages before exploring further. # Example: Custom Trigger for EmailMessage ``` trigger InboundEmailMessageTrigger on EmailMessage (before insert) { List incomingEms = new List(); // if use own trigger boolean is false, then stop this trigger and use the PCIFY managed package one if (!pcify.Manager.useOwnTrigger(pcify.StaticUtils.EMAILMESSAGE)) { return; } // if Detection is turned on for Email Message if (pcify.Manager.getManager(pcify.StaticUtils.EMAILMESSAGE).pcify__isActive__c) { // collect incoming emails for (EmailMessage em : Trigger.new) { if (em.Incoming) { incomingEms.add(em); } } // process all incoming with PCIFY pcify.Processor.maskCreditCards( incomingEms, pcify.Manager.getMaskFields(pcify.StaticUtils.EMAILMESSAGE), pcify.StaticUtils.EMAILMESSAGE ); } } ```