• jhoskins_orl
  • NEWBIE
  • 0 Points
  • Member since 2010

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies

What is the best approach for a trigger to only fire once, after my IF condition has been met? The code below operates as it should once the IF condition is met - case is created.
 
However, the account could remain in the IF condition state for a couple of days. In the mean time, a simple update to the account could occur (e.g. phone number update) which would fire the trigger (again) thus a second (duplicate) case is created - not so good.
 
Where does my code need to be modified to prevent this behavior? I only need to have the trigger fire once when the original IF statement criteria is met. Of course, if the account falls out of the IF statment condition and then back in, the trigger would fire again - that's expected behavior.

 

Thanks.

 

 

trigger CreateVenereRequestIdCase on Account (before update) {

Case[] newCase = new Case[0];
for (Account a : Trigger.new) {
Account beforeUpdate = System.Trigger.oldMap.get(a.Id);
if((a.RecordTypeId == '012700000009Tor' || a.RecordTypeId == '012700000009JNI')
&& a.Venere_Module_ID__c == null && a.Venere_ID__c == null && a.Request_Venere_ID__c == TRUE && beforeUpdate.Request_Venere_ID__c == FALSE)
system.debug('Here is the account id: ' + a.Id);
newCase.add(new Case(
accountID = a.id,
Origin = 'Market Manager',
Priority = 'Medium',
RecordTypeID = '012T00000000Obu', //HDM - Venere Request ID
Status = 'New',
Subject = 'Venere ID Request',
Description = 'Please create a new Venere ID for ' + a.Name)
);

}
insert newCase;

}