function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Yannick Berthoud 7Yannick Berthoud 7 

create task if opportunity closedate is d-5 ?

Hello,

How can I create task to the opportunity OwnerId if the Opportunity.StageName != "closed" and Opportunity.CloseDate is to D-5 ?

This functions must be checked every day except week-end

Thanks per advance,

Yannick
Alain CabonAlain Cabon
Hello Yannick,

"This functions must be checked every day except week-end": You want to prevent the sending of tasks during the week-ends (so the sendings must occur the next Monday or the previous Friday?)

There are several solutions but that depends on the previous condition (workflow rules, process builder, apex) and you don't need a scheduled daily task. 

Basically, you just need a Time-Based Workflow ( FAQ https://help.salesforce.com/articleView?id=000005245&type=1 ) with the specific problem of How to retroactively trigger workflow on already existing records?  https://help.salesforce.com/articleView?id=How-to-retroactively-trigger-workflow-on-already-existing-records&language=en_US&type=1  if the tasks can be sent during the week-ends.

Can I configure multiple actions to occur at different points in time for the same rule?
Yes, you can create a timeline of actions by configuring multiple time triggers and defining actions for each one.
Example: Consider a rule for all high value opportunities (value > $500K, probability > 70%). The immediate actions could include sending an email alerts to the Account team stating that a new high value Opportunity has been created. The time-dependent actions could include the following: 10 days before the Opportunity close date, assign a Task to the Opportunity owner to follow up with the customer.
7 days before Opportunity close date, change the owner of the Opportunity to VP Sales, and send an email alert to the new owner.
https://help.salesforce.com/articleView?id=000005245&type=1

Regards
Yannick Berthoud 7Yannick Berthoud 7
Hi Alain,

Thanks for your answer.
 
"This functions must be checked every day except week-end": You want to prevent the sending of tasks during the week-ends (so the sendings must occur the next Monday or the previous Friday?)

I think for the previous friday is the best. When I try to create the workflow rules, based on "created or updated" with opportunity close date = TODAY() + 5. I have an error about invalid format
User-added image

I think I leave false ^^

thanks per advance

Yannick
Yannick Berthoud 7Yannick Berthoud 7
I think I created the temporal workflow successfuly:

User-added image

On the other hand, without the weekend support
Alain CabonAlain Cabon
Hi Yannick,

You are close to the complete solution. It is the good way.
The  criteria can be also a formula by the way (drop down).

For new developments, you should try to use the Process Builder instead of the Worflow rules.

Workflow Rule Migration: Say Goodbye to Workflow and Hello to Process Builder
Process Builder is the future.

We’re no longer enhancing Workflow. We still support your use of workflow rules, and will continue to do so. But all new functionality for the workflow use case will come through Process Builder. If you want to use the shiny new functionality, migrate your automation to Process Builder.
Now you have all the information you need to decide between Workflow and Process Builder for future projects.

https://trailhead.salesforce.com/en/modules/workflow_migration/units/workflow_migration_intro

A+
Alain