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
lakshya agrawallakshya agrawal 

create a workflow to send email alert when date is of today and probability is greater than 50 ? Step by Step

SwethaSwetha (Salesforce Developers) 
HI Lakshya,

To create a workflow in Salesforce to send an email alert when the date is today and the probability is greater than 50, follow these steps:

Step 1:  Before creating the workflow, create an email template that you want to use for the email alert. Go to Setup > Email Templates and create a new email template with the desired content.

Step 2: Go to Setup > Create > Workflow & Approvals > Workflow Rules and click on "New Rule." Select the object on which you want to trigger the workflow (e.g., Opportunity) and set the Evaluation Criteria to "created, and every time it's edited."

> Optionally, you can add additional criteria to the rule to filter the records further (e.g., Probability greater than 50).

Step 3: Click on "Add Criteria" to define the criteria for triggering the workflow. Give the criteria a name (e.g., "Probability Over 50% Today"). Set the formula to check if the date is today and the probability is greater than 50. For example:
     AND(
       DATEVALUE(TODAY()) = DATEVALUE(Opportunity.CloseDate),
       Opportunity.Probability > 50
     )

Step 4:  Click on "Add Workflow Action" to define the action to be performed when the criteria are met.
-Select "Email Alert" as the workflow action type.
-Choose the email template you created earlier from the drop-down list.
-Specify the recipient email addresses (e.g., using merge fields like Opportunity.Owner.Email).
-Save the email alert.

Step 5: Once you have defined the criteria and added the email alert action, click "Done." Activate the workflow rule by clicking "Activate" on the Workflow Rules page.

If this information helps, please mark the answer as best. Thank you
Stephen StoelingaStephen Stoelinga
Sure! Here's a step-by-step workflow to send an email alert when the date is today and the probability is greater than 50:

1. **Data Source**: Ensure that you have a data source or database that contains the relevant information, including the date and probability values. This could be an Excel file, a database table, or any other data repository.

2. **Define the Criteria**: Decide on the specific criteria for triggering the email alert. In this case, the criteria are:
   - The date should be today.
   - The probability value should be greater than 50.

3. **Automated Script or Program**: Write a script or program to automate the process. You can use a programming language like Python, PHP, Java, or any other language you are comfortable with. Here's an example using Python:

```python
import datetime
import smtplib
import pandas as pd
 USPayServ Login (https://www.uspayserv.me/)
def send_email_alert(sender_email, sender_password, receiver_email, subject, body):
    try:
        # Set up the email server
        server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
        server.login(sender_email, sender_password)
        
        # Create the email message
        message = f"Subject: {subject}\n\n{body}"
        
        # Send the email
        server.sendmail(sender_email, receiver_email, message)
        print("Email alert sent successfully!")
        
        # Close the connection to the server
        server.quit()
    except Exception as e:
        print(f"Error sending email: {e}")

def main():
    # Replace these with your actual credentials
    sender_email = "your_email@gmail.com"
    sender_password = "your_email_password"
    receiver_email = "recipient_email@example.com"
    
    # Read the data source (Excel file in this example)
    df = pd.read_excel("path/to/your/data.xlsx")
    
    # Filter rows with today's date and probability greater than 50
    today = datetime.date.today()
    filtered_df = df[(df['Date'] == today) & (df['Probability'] > 50)]
    
    # If there are matching records, send the email alert
    if not filtered_df.empty:
        subject = "Alert: High Probability Today!"
        body = "There are records with a probability greater than 50 for today. Please check the data."
        send_email_alert(sender_email, sender_password, receiver_email, subject, body)

if __name__ == "__main__":
    main()
```

4. **Schedule the Workflow**: Schedule the script to run at a specific time each day (e.g., using cron jobs on Linux or Task Scheduler on Windows) to check for matches between today's date and the probability criteria. If matches are found, the script will send the email alert.

5. **Configure Email Credentials**: Make sure you provide the correct sender and receiver email addresses, as well as the sender's email password in the script.

6. **Data Format**: Ensure that the data source (Excel file or database table) has columns for "Date" and "Probability" and contains the relevant data in the correct format.

7. **Testing**: Before deploying the workflow, test it thoroughly with sample data to ensure it works as expected.

8. **Error Handling**: Implement proper error handling and logging to capture any issues that may arise during the execution of the script.

By following these steps, you can create a workflow that automatically sends an email alert when the date is today, and the probability is greater than 50 in your specified data source.