• charlesko
  • NEWBIE
  • 0 Points
  • Member since 2009

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 5
    Replies

This is my first time writing a trigger with 'before update'. It simply doesn't get triggered. The test method returns success, but in real world, it's like the trigger isn't there at all.

 

This contact trigger is supposed to change a value of a custom field in case whenever it is updated and has EmailBouncedDate not null. The purpose of this trigger is to alert the case viewer that this contact's email address is invalid. The code I wrote is below.

 

I tried slipping in some other random things outside of the if statement just to see if the trigger runs at all, and it doesn't seem like it is.

 

Isn't a trigger supposed to run everytime any value in the sObject is changed?

 

 

trigger BouncedEmailHandler on Contact (before update) {

for (Contact updatedContact : trigger.new) {

if(updatedContact.EmailBouncedDate != null){
for (Case c : [SELECT Id, Need_Attention__c, Status, Invalid_Contact_Email__c FROM Case WHERE Case.contactId =: updatedContact.Id]) {

System.debug('Trigger executed');
//c.Status = 'Invalid Contact Email';
c.Need_Attention__c = true;
c.Invalid_Contact_Email__c = true; update c;

}
}

//test code - let's see if this is triggered at all
Contact[] cc = [SELECT Id, Phone FROM Contact WHERE Contact.Id =: updatedContact.Id LIMIT 1];
cc[0].phone = '111111111'; update cc;


}

}

 

 

 

Message Edited by charlesko on 11-04-2009 10:34 AM

Hi all,

 

I'm a newbie in SF development area. I have a quick question about the triggers.

 

I read that update() in APEX is like UPDATE in SQL, so an "after update trigger"should fire whenever there is any change to any entry in sObject. Is this right?

 

The reason I'm asking this is that I have written a trigger that updates a field in a case when Account's PersonBouncedEmailDate is updated. So when we get a bounce email, it will update the PersonBouncedEmailDate for the row in Account, and that should fire this trigger I wrote which will update a custom field. (You can kind of guess where my company's using this trigger).

 

This trigger is however isn't firing at all. It fires when I manually update one of the fields (phone for example), but it doesn't fire when we get bounced email.

 

Any help will be appreciated.

 

 

This is my first time writing a trigger with 'before update'. It simply doesn't get triggered. The test method returns success, but in real world, it's like the trigger isn't there at all.

 

This contact trigger is supposed to change a value of a custom field in case whenever it is updated and has EmailBouncedDate not null. The purpose of this trigger is to alert the case viewer that this contact's email address is invalid. The code I wrote is below.

 

I tried slipping in some other random things outside of the if statement just to see if the trigger runs at all, and it doesn't seem like it is.

 

Isn't a trigger supposed to run everytime any value in the sObject is changed?

 

 

trigger BouncedEmailHandler on Contact (before update) {

for (Contact updatedContact : trigger.new) {

if(updatedContact.EmailBouncedDate != null){
for (Case c : [SELECT Id, Need_Attention__c, Status, Invalid_Contact_Email__c FROM Case WHERE Case.contactId =: updatedContact.Id]) {

System.debug('Trigger executed');
//c.Status = 'Invalid Contact Email';
c.Need_Attention__c = true;
c.Invalid_Contact_Email__c = true; update c;

}
}

//test code - let's see if this is triggered at all
Contact[] cc = [SELECT Id, Phone FROM Contact WHERE Contact.Id =: updatedContact.Id LIMIT 1];
cc[0].phone = '111111111'; update cc;


}

}

 

 

 

Message Edited by charlesko on 11-04-2009 10:34 AM