Example: Custom Trigger for EmailMessage
  • 13 Jul 2022
  • 1 Minute to read
  • Dark
    Light

Example: Custom Trigger for EmailMessage

  • Dark
    Light

trigger InboundEmailMessageTrigger on EmailMessage (before insert) {
    List<EmailMessage> incomingEms = new List<EmailMessage>();

    // 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
        );
    }
}