1

I have a field called Contract on the lead object. I also have a formula field called 'Contract Number' on the Lead object which should get populated with the Date that the 'Contract' field was populated.

I cannot use Workflow because there is batch apex updating the 'Contract Date' field so it needs to be the formula field I have created. The 'Contract' field will only be updated once and will not change therefore the Contract Date should be the same. Any ideas?

  • why can't you use workflow in batch apex? – Guy Dec 10 '14 at 10:45
  • Workflow will only update the lead record if it has been Edited and Saved. Formula fields update as soon as a record is refreshed. A batch will run in the background every hour which will update the Contract field on the lead. When this gets update, the Contract Date field should then be updated with date (TODAY) of when the Contract field gets populated. Make sense? – Clehan1 Dec 10 '14 at 14:02
  • this will work perfectly well with workflow. And it can't be done with formula fields. – Guy Dec 10 '14 at 15:02
  • I don't understand how? Could you shine some light on this? in my mind the Workflow will run when the record is created /created & edited etc. The lead records may not be edited after the Contract field gets updated. – Clehan1 Dec 10 '14 at 19:21
  • A formula field won't work because you can't determine when the field value changes. You would only be able to check whether or not the Contract Number field had a value in it or not, not the date that it was updated, and the check would be done every time the formula field is viewed or accessed in another formula, because the value is calculated is at runtime. Guy's answer below should work. – shannonsans Dec 10 '14 at 22:33
0

So if I understand correctly, the requirement is this:

A batch will run in the background every hour which will update the Contract field on the lead. When this gets update, the Contract Date field should then be updated with date (TODAY) of when the Contract field gets populated.

So the steps to take are:

  1. create a workflow rule on Lead, triggering only on "created, and any time it’s edited to subsequently meet criteria". Criteria should be: Contract not equal to ''.
  2. add a field update to the workflow rule. The field update should update the Contract_Date field to value TODAY() (use the formula editor to set that value).

That should do it. The workflow will run only once (when the Contract field goes from empty to non-empty).

  • This worked perfectly, thanks. I was under the impression that 'created, and any time it’s edited to subsequently meet criteria' would only update if the record was 'physically' edited by the user and then saved. Obviously I was wrong! – Clehan1 Dec 11 '14 at 9:55
  • Glad to be of help. Maybe you can accept the answer, so others might find it easier and profit. (and also it's better for the site statistics :-) – Guy Dec 11 '14 at 10:02

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.