0% found this document useful (0 votes)
4 views

10 october salesforce

The document outlines the steps to create a workflow rule in Salesforce that triggers email alerts when the Opportunity Close Date is changed. It includes detailed instructions on logging in, navigating to workflow rules, defining criteria, creating email alerts, and testing the workflow. Additionally, it provides sample code for handling email alerts and testing the functionality within Salesforce's Apex framework.

Uploaded by

Rahul Kumar Jha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

10 october salesforce

The document outlines the steps to create a workflow rule in Salesforce that triggers email alerts when the Opportunity Close Date is changed. It includes detailed instructions on logging in, navigating to workflow rules, defining criteria, creating email alerts, and testing the workflow. Additionally, it provides sample code for handling email alerts and testing the functionality within Salesforce's Apex framework.

Uploaded by

Rahul Kumar Jha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

To create a workflow rule in a system like Salesforce that sends email alerts when

the Opportunity Close Date has been changed, you can follow these steps:

1. **Log In to Your Salesforce Account**: Ensure you are logged in to your


Salesforce account with the necessary permissions to create workflow rules.

2. **Navigate to Workflow Rules**:


- In Salesforce Classic: Go to Setup > Create > Workflow Rules.
- In Lightning Experience: Go to Setup > Object Manager > [Select the Object
where Opportunity is] > Workflow Rules.

3. **Create a New Workflow Rule**:


- Click on "New Rule."

4. **Select the Object**:


- Choose the Opportunity object as the object for which you want to create the
rule.

5. **Define the Evaluation Criteria**:


- Choose when the rule should be triggered. In this case, you want it to trigger
whenever the Opportunity Close Date is changed. So, select "created, and every time
it's edited."

6. **Specify the Rule Criteria**:


- You can add criteria that define when the rule should run. Since you want to
trigger the rule whenever the Close Date is changed, you can set the rule criteria
to be something like:
- Rule Name: Close Date Changed
- Formula evaluates to `ISCHANGED(CloseDate)`

7. **Define Workflow Actions**:


- Click on "Add Workflow Action" and choose "New Email Alert."

8. **Create the Email Alert**:


- Fill in the necessary details for the email alert:
- Email Alert Name: Close Date Changed Alert
- Recipient Type: Choose the appropriate recipient (e.g., User, Contact,
Lead).
- Recipient: Select the specific user or email address.
- Related To: Choose "Opportunity."
- Email Template: Select or create an email template that suits your
notification.
- Additional Email Fields: Customize the email fields as needed (e.g., CC,
BCC).
- Specify the email subject and body.

9. **Activate the Workflow Rule**:


- After configuring the workflow rule and email alert, make sure to activate the
rule by clicking the "Activate" button.

10. **Test the Workflow Rule**:


- To ensure that the workflow rule works as expected, create or edit an
Opportunity record and change the Close Date. You should receive an email alert if
the Close Date is modified.

11. **Monitor and Adjust**:


- After implementing the workflow rule, monitor its performance and adjust it
as needed to meet your requirements.
That's it! You've created a workflow rule in Salesforce that sends email alerts
whenever the Opportunity Close Date is changed. Make sure to customize the rule and
email alert settings to fit your organization's specific needs and email templates.

Hello,

The Close Date for Opportunity: {!Opportunity.Name} has been changed.

Old Close Date: {!Opportunity.CloseDate}


New Close Date: {!Opportunity.CloseDate}

Thank you.

https://espire-infolabs--prodpart.sandbox.lightning.force.com/lightning/setup/
CommunicationTemplatesEmail/page?address=%2F00XPv0000001bQX%3Fsetupid
%3DCommunicationTemplatesEmail

00XPv0000001bQX

https://espire-infolabs--prodpart.sandbox.lightning.force.com/lightning/setup/
CommunicationTemplatesEmail/page?address=%2F00XPv0000001bQX%3Fsetupid
%3DCommunicationTemplatesEmail

OpportunityCloseDateTrigger: execution of BeforeUpdate caused by:


System.StringException: Invalid id: YOUR_TEMPLATE_ID
Class.EmailAlertHandler.sendEmailAlerts: line 9, column 1
Trigger.OpportunityCloseDateTrigger: line 19, column 1

public class EmailAlertHandler {


public static void sendEmailAlerts(List<Opportunity> opportunities) {
List<Messaging.SingleEmailMessage> emailMessages = new
List<Messaging.SingleEmailMessage>();

for (Opportunity opp : opportunities) {


Messaging.SingleEmailMessage email = new
Messaging.SingleEmailMessage();
email.setTemplateId('00XPv0000001bQX'); // Replace with your email
template ID
email.setTargetObjectId(opp.Id);
emailMessages.add(email);
}

Messaging.sendEmail(emailMessages);
}
}

public class EmailAlertHandler {


public static void sendEmailAlerts(List<Opportunity> opportunities) {
List<Messaging.SingleEmailMessage> emailMessages = new
List<Messaging.SingleEmailMessage>();

for (Opportunity opp : opportunities) {


Messaging.SingleEmailMessage email = new
Messaging.SingleEmailMessage();
email.setTemplateId('00XPv0000001bQX'); // Replace with your email
template ID
email.setTargetObjectId(opp.Id);
emailMessages.add(email);
}

Messaging.sendEmail(emailMessages);
}
}

trigger OpportunityCloseDateTrigger on Opportunity (before update) {


List<Id> opportunityIds = new List<Id>();
List<Opportunity> updatedOpportunities = new List<Opportunity>();

for (Opportunity newOpp : Trigger.new) {


Opportunity oldOpp = Trigger.oldMap.get(newOpp.Id);
if (newOpp.CloseDate != oldOpp.CloseDate) {
opportunityIds.add(newOpp.Id);
updatedOpportunities.add(newOpp);
}
}

if (!opportunityIds.isEmpty()) {
// Call a method to send email alert
EmailAlertHandler.sendEmailAlerts(updatedOpportunities);
}
}

@isTest
public class EmailAlertHandlerTest {
@isTest
static void testEmailAlertHandler() {
// Create a test Opportunity
Opportunity testOpportunity = new Opportunity(
Name = 'Test Opportunity',
CloseDate = Date.today(),
StageName = 'Closed Won',
// Add other required fields
);
insert testOpportunity;

// Create an Email Template for the test


EmailTemplate testTemplate = new EmailTemplate(
Name = 'Test Template',
DeveloperName = 'Test_Template',
Subject = 'Test Email',
Body = 'This is a test email template.',
TemplateType = 'text',
IsActive = true
);
insert testTemplate;

// Assign the email template's ID to the EmailAlertHandler


EmailAlertHandler.sendEmailAlerts(new List<Opportunity>{testOpportunity});

// Verify that the email messages have been created


List<Messaging.SingleEmailMessage> emailMessages = [SELECT Id FROM
Messaging.SingleEmailMessage];
System.assertEquals(1, emailMessages.size(), 'Email message not created.');

// More assertions can be added for email content, recipients, etc.


}
}

@isTest
public class OpportunityCloseDateTriggerTest {
@isTest
static void testOpportunityCloseDateTrigger() {
// Create a test Opportunity
Opportunity testOpportunity = new Opportunity(
Name = 'Test Opportunity',
CloseDate = Date.today(),
StageName = 'Closed Won',
// Add other required fields
);
insert testOpportunity;

// Change the CloseDate to trigger the trigger


testOpportunity.CloseDate = Date.today().addDays(1);
update testOpportunity;

// Verify that an email message has been created


List<Messaging.SingleEmailMessage> emailMessages = [SELECT Id FROM
Messaging.SingleEmailMessage];
System.assertEquals(1, emailMessages.size(), 'Email message not created.');

// More assertions can be added for email content, recipients, etc.


}
}

https://espire-infolabs--prodpart.sandbox.lightning.force.com/lightning/setup/
ManageUsers/page?address=%2F0058E00000B9lch%3Fnoredirect%3D1%26isUserEntityOverride
%3D1

0058E00000B9lch
https://espire-infolabs--prodpart.sandbox.lightning.force.com/lightning/setup/
CommunicationTemplatesEmail/page?address=%2F00XPv0000001bQX%3Fsetupid
%3DCommunicationTemplatesEmail

00XPv0000001bQX

I am writing to inform you that I am in need of a leave of absence from work due to
a severe fever. I have been experiencing a fever for the past few days and it has
not subsided.

I have consulted my doctor and they advise that I take some time off to rest and
recover. I am unsure of how long I will need off, and would like to keep you
informed of my progress.

I am available to answer any questions or provide any documentation necessary. I am


sorry for any inconvenience this may cause, and I look forward to being able to
return to work soon.

https://espire-infolabs--prodpart.sandbox.lightning.force.com/lightning/setup/
CommunicationTemplatesEmail/page?address=%2F00XPv0000001bQX%3Fsetupid
%3DCommunicationTemplatesEmail

public class EmailAlertHandler {


public static void sendEmailAlerts(List<Opportunity> opportunities) {
List<Messaging.SingleEmailMessage> emailMessages = new
List<Messaging.SingleEmailMessage>();

for (Opportunity opp : opportunities) {


Messaging.SingleEmailMessage email = new
Messaging.SingleEmailMessage();
email.setTemplateId('00XPv0000001bQX'); // Replace with your email
template ID
email.setTargetObjectId(opp.Id);
emailMessages.add(email);
}

Messaging.sendEmail(emailMessages);
}
}

public class EmailAlertHandler {


public static void sendEmailAlerts(List<Opportunity> opportunities) {
List<Messaging.SingleEmailMessage> emailMessages = new
List<Messaging.SingleEmailMessage>();
for (Opportunity opp : opportunities) {
// Retrieve the Contact associated with the Opportunity
Contact relatedContact = [SELECT Id FROM Contact WHERE Id
= :opp.ContactId LIMIT 1];

if (relatedContact != null) {
Messaging.SingleEmailMessage email = new
Messaging.SingleEmailMessage();
email.setTemplateId('00XPv0000001bQX'); // Replace with your email
template ID
email.setTargetObjectId(relatedContact.Id); // Set the Contact as
the targetObjectId
emailMessages.add(email);
}
}

Messaging.sendEmail(emailMessages);
}
}

https://espire-b-dev-ed.develop.lightning.force.com/lightning/setup/
CommunicationTemplatesEmail/page?address=%2F00X2w000000rCuO%3Fsetupid
%3DCommunicationTemplatesEmail

00X2w000000rCuO

Hi,
I have Salsforce production account with user name [email protected] with
profile as admin ,when I am trying to login it say's contact to your admin ,but
only i am the admin of this org,and when I click on forgot pasword It ask for user
name and send mail to my account but the link sent by salesforce does not reset
password option
so irequest to you please help me to recover my account

You might also like