My_Test_Repo/force-app/main/default/triggers/BrevoTrigger.trigger

26 lines
1.2 KiB
Plaintext

trigger BrevoTrigger on Contact (after insert, after update, after delete) {
if (Trigger.isAfter) {
if (Trigger.isInsert) {
for (Contact con : Trigger.new) {
if (con.Email != null && con.Phone != null) {
BrevoContactTrigger_Handler.createContactInBrevo(con.Email, con.FirstName, con.LastName, con.Phone,con.Id);
}
}
} else if (Trigger.isUpdate) {
for (Contact con : Trigger.new) {
if (con.Email != null && con.Phone != null) {
Contact oldContact = Trigger.oldMap.get(con.Id);
if (con.FirstName != oldContact.FirstName || con.LastName != oldContact.LastName || con.Phone != oldContact.Phone) {
BrevoContactTrigger_Handler.updateContactInBrevo(con.Email, con.FirstName, con.LastName, con.Phone, con.Id);
}
}
}
} else if (Trigger.isDelete) {
for (Contact con : Trigger.old) {
if (con.Email != null) {
BrevoContactTrigger_Handler.deleteContactInBrevo(con.Email);
}
}
}
}
}