+ Start a Discussion
NewCoderBoyNewCoderBoy 

beginning developer needing help

hello everyone.  I'm new to the salesforce team at my company and I need help writing my first apex trigger.   I need my trigger to stop an email alert from a workflow rule.  stop the email from going out whenever the following field has a date: Initial Field Visit Completed.   what's been happening is the emails have been going out when the date has been updated.  the only way to update the child record from the parent and have it fire the workflow rule would be to us a trigger.   The workflow rule looks like this:

AND(
OR(
AND(Effort__r.RecordTypeId = '01250000000UISS', Effort__r.Inactive__c = False, Effort_Probability__c < 0.2),
AND(Effort__r.RecordTypeId = '01250000000UISQ', Effort__r.Inactive_FiNet__c = 'False',
OR(Effort_Probability__c < 0.33, ISBLANK(Effort__r.Initial_Field_Visit_Completed__c)))
),

ISPICKVAL(Lead_Source__c , "External Recruiter"),
NOT(ISBLANK(Lead_Accepted_Date__c)),
ISBLANK(Lead_Disqualified_Date__c),
ISBLANK(Lead_Expired_Date__c),
Inactive__c = False,
ER_Email__c <> "",
Today() <= DQ_Reminder_Date__c


)

Could you guys give me ideas on how to write the trigger to make sure the emails stop when the date has been entered?

thank you.

Chad
MaxPowerForceMaxPowerForce
It sounds like you have a time based workflow rule, but the time trigger is not cancelled when a field on the related record is updated?  I suppose you need to do a dummy update on the child records to retrigger evaluation of the workflow rule thereby cancelling the action. 

You can certainly do this with a trigger.  I don't know the type from the child record so I just called it childrenRecord__c.  I didn't test this code, but it probably will work once you fix the childrecord name.

trigger dummyUpdate on Effort__c (after insert, after update) {
     
    // Get child records that require a dummy update using the Ids in the trigger.newmap.keySet()
    childRecord__c[] children = [SELECT Id from childrecord__c WHERE Effort__c in :trigger.newMap.keySet()];

   // Update the child records to retrigger workflow evaluation criteria
   update children;

}