1

I'm going round in circles trying to figure out how to approach this one -

  • I have a Contract with an end date
  • The Contract has a child object (Contract Work)
  • Contract Work has tasks

I want to write a trigger that generates an alert when a Task is inserted with a date later than the end date of the Contract.

I have to figure out if the Task parent is a Contract Work record and if it is, compare the Contract Work's parent Contract End Date with the ActivityDate of the Task.

I've been trying to do it with sets and maps but I'm not there yet.

Any help in how to tackle this would be greatly appreciated.

Many Thanks, Mike.

0

Write a trigger on after insert and after update of task. Add all whatId values to a set. Then query contact work object with where clause "Where id=:setVariable". In the same query you can access Contract__r.End_Date__c also. Then once again iterate over trigger.new and query result and compare the dates. By alert, what did you mean?. Sending email to someone?

2
  • Thanks Victor - much appreciated. That's encouraging that I'm on the right track :-) By 'alert', yes, I mean an email. I have some code in another trigger that I pulled together where I've got this working. – MikeA May 8 '15 at 10:11
  • Please keep in memory that you can send only 10 emails in one apex transaction. If you are doing bulk task load through dataloader, it might create problem. – Victor May 8 '15 at 15:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.