Let's define some identifiers before we start, in order to make things clear.

  • I have some Account objects and some related Opportunity objects.
  • Each Account object has a Access__c field.
  • Each Opportunity object have a start date and an end date fields.

My requirements are that:

  • once an opportunity begins to start(the day of start date), we need to set the Access__c field of it's related Account to be Yes.
  • once an opportunity begins to finish(the day of finish date), we need to set the Access__c field of it's realted Account object to be Expired.

Please note that I can not use Apex Trigger to help me with this, becasue from my understanding, apex trigger need a explictly event like object insert/update/delete to trigger the pre-defined action.

However, in my case, there are no such event, but a date field. We want the Access__c field to be updated automatically based on the date field.

After some research, I tried to do it by time-dependent workflow.

So I added two time-dependent trigger(not apex trigger) in my workflow.

  • One action is to set Access__c to be Yes when date equals to start date of Opportunity.
  • The other action is to set Access__c to be Expired when date equals to end date of Opportunity.

For example we have the following objects.

  • Account A1 has two related opportunities O1 and O2.
  • O1 has start date d1 and end date d2.
  • O2 has start date d3 and end date d4.
  • O1 is added to A1 first, and O2 was added to A1 later.
  • d1 and d2 are less than d3 and d4.

Let's consider a general case where we have A1,O1,O2 with d2 + 5 = d3.

This means that, the second Opportunity begins to start 5 days after the first Opportunity finish.

According to my pre-defined workflow, - The Access__c of A1 will be updated to Expired at d2. - And 5 days later, at d3, the Access__c of A1 will be updated to Yes. - My workflow works well for this general case.

But let's consider one more specific case where d3=d2.

According to my pre-defined workflow,

  • At d2, the Access__c of A1 will be updated to Expired. (1)

  • At d3, the Access__c of A1 will be updated to Yes. (2)

Since d2=d3, the above two actions will be executed at the same time. What's more, the are updating the same field with different values.

Even thought, I can see my scheduled actions (1) are listed before (2). But I'm not sure if they are executed according to the list sequence.

Can someone confirm if the scheduled actions will be executed exactly according to the sequence list?

Or can someone provide me a way to make sure that (1) is executed before (2).

  • How have you got on with implementing this so far?
    – Alex S
    Commented Jul 17, 2015 at 7:56
  • Hi, Alex. You are the first person who answered my question. I am so appreciated. I have searched a lot, even can not find a similar problem. I am not a native English speaker, and I am not sure if I have described my question clearly.
    – yuan
    Commented Jul 17, 2015 at 9:58
  • Your English is great! But just to check, on the last line of your question, you mention an "Account__c" field for the first time, did you mean to put "Access__c"? It sounds like you could just create a workflow rule for the Access__c field to set it to "Yes", when it's changed to "Expired". Then there would be no need to make the second rule time dependent or am I misunderstanding something?
    – Alex S
    Commented Jul 17, 2015 at 10:02
  • Hi @AlexS, thanks for pointing out my misspelling. I've made comments on my original question. Do you have any ideas? By the way, do you know how can I let more people see my question and then help me? Actually, this is the first question I've ever asked in the stackexchange, and I have no idea how to do.
    – yuan
    Commented Jul 18, 2015 at 15:20
  • That looks good. As far as increasing the visibility of your question, the edit will push it to the top of 'active' question lists but there's relatively fewer users on SE at the weekend. You could also try sharing on Twitter but apart from that you just need to wait and see. I'll take another look at this later, now that you've updated your requirements.
    – Alex S
    Commented Jul 18, 2015 at 15:25

2 Answers 2


My suggestion will be to set it up like this

Opportunity 1:- Start date: Aug 5 ; End date: Aug 11 Opportunity 2:- Start date: Aug 11 ; End date: Aug 14 Opportunity 3:- Start date: Aug 14 ; End date: Aug 19

Create a workflow (i guess you have already done this) 1. set Access__c = Yes at start date + 0 hrs 2. set Access__c = Expired at end date + 0 hrs

This will automatically take care of all the opportunities. While executing at Aug 11, there'll be two workflow that'll get fired 1. Workflow for Opportunity 1: to set Access__c = Expired 2. workflow for opportunity 2: to set Access__c = Yes

Hope it helps

  • Thanks @Anshul. Actually, the start date of Opportunity 2 need to be at least one day behind the expiry date of Opportunity 1. But in your example, we still can talk about the key problem. You mentioned that two workflows will get fired at the same time. That's correct. But the right logic is that we need to make sure that workflow for Opportunity 1 should be first execute and the the workflow for Opportunity 2. Let me know if my description is not clear.
    – yuan
    Commented Jul 18, 2015 at 16:53
  • Yuan, you cannot control sequence of workflow execution. So, if that is a "must" requirement, then i'll suggest you to explore implementing this requirement using apex triggers, where you can programmatically control sequence of actions.
    – Anshul
    Commented Jul 19, 2015 at 17:55
  • Hi @Anshul. I did a little research about apex triggers. And it's said that this need a event like object insert/update/delete to trigger the actions. However, there is not an explicit event in my case. All I want is to monitor the date field and do an action in a scheduled date automatically. Do you have any idea how apex trigger can be working in my case? Thanks.
    – yuan
    Commented Jul 20, 2015 at 3:37
  • Oops. I lost track of your requirements. You can make use of Scheduled apex. Wherein, an apex job will run each day (at predefine time) and pull all opportunities which are to be activated/ inactivated and then followed by required business logic. For more details on scheduled apex refer developer.salesforce.com/docs/atlas.en-us.apexcode.meta/…
    – Anshul
    Commented Jul 20, 2015 at 7:11
  • Hi @Anshul. Using scheduled apex should be working. But doing it by this way may spent more resources, because it may need to run daily. So it might not be a good idea :)
    – yuan
    Commented Jul 20, 2015 at 7:27

So to summarise your problem (correct me if I'm wrong), you need to be able to set the Access__c field to 'Yes' if there are any Opportunities with a start date that's equal to or less than today and an end date that's greater than today.
The challenge - to state the obvious - is that your workflow rule on the Opportunity can't evaluate other related Opportunities, to determine whether the Access__c field should be updated.

The solution is to count the number of Opportunities which meet your criteria for a live Opportunity and to roll-up that number to an Account field. Then if that count is changed and is now greater than 0, change the Access__c value to 'Yes' and if it's changed and now equals 0, change the Access__c value to 'Expired'.

Unfortunately, standard roll-ups don't support dynamic criteria so you can't filter the rollup to count Opportunities with a start date greater than today(), you can only filter based on a static date.

Instead, you can use Passage Technology's Rollup Helper app (you can set up 3 free roll-ups, before having to pay for more) which lets you set your filter criteria and then insert the count of matching records into a target field on the parent record.
To keep the count up to date, schedule the roll-up to run each night. You can schedule recurring roll-ups with this app.

Then you can set your workflow on the Account to trigger the field update on Access__c whenever the value of the field containing your count (the target field) is changed from 0 to 1 or vice versa.

  • @yuan thanks for the feedback. I don't think your question could be any clearer now and yes it's the order of the field updates that's the issue. Since the order can't be guaranteed or controlled..my answer's the same :) it's basically utilising batch apex updates (which can be scheduled) but without you having to write any code & that's why it's complex. It would be a lot simpler if SF allowed relative date filters for roll-ups but they don't (because normal roll-ups need a trigger to recalculate too) so there you go. PS please leave feedback on Answers, rather than Questions
    – Alex S
    Commented Jul 20, 2015 at 6:06
  • @yuan if you ignore the complexity of implementing the solution itself what I'm proposing is actually quite simple. Count the number of 'live' Opportunities related to your Accounts. Then if that number changes, for a particular Account, change it's Status to either 'Yes' or 'Expired'. And that's it!
    – Alex S
    Commented Jul 20, 2015 at 6:11
  • LOL. Thanks @Alex for your kind patience. Batch Apex is more familiar for me. I will look at your solution and provide feedbacks. Thanks again.
    – yuan
    Commented Jul 20, 2015 at 6:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .