In lots of MuleSoft integration initiatives, there’s a requirement to create lead or case information in Salesforce. Organizations sometimes use the lead project rule and case project rule to routinely assign new leads or circumstances to the customers or queue.
Once we create leads or circumstances from MuleSoft utilizing the Salesforce connector, by default it doesn’t set off the project guidelines and doesn’t ship e mail notifications to homeowners.
This weblog describes the method of triggering Salesforce lead or case project guidelines and sending e mail notifications to homeowners when creating information from MuleSoft. We’ll assume that the salesforce project guidelines are already arrange and which get triggered when creating leads or circumstances from the salesforce UI. We will likely be specializing in triggering project guidelines in Salesforce when creating a brand new lead or case from Mulesoft. This weblog won’t cowl easy methods to create project guidelines in Salesforce.
Background
Salesforce Project Guidelines
Project guidelines in Salesforce are used to routinely assign a lead or case to the proprietor (consumer or queue).
Salesforce gives two forms of project guidelines:
- Lead project rule: That is used to specify how leads are assigned to customers or queues.
- Case project rule: That is used to find out how circumstances are assigned to customers or put into queues.
When a brand new lead or case is created it triggers the project rule in addition to sends the notification e mail to the assignee if the ship e mail checkbox is enabled. For instance: Within the beneath screenshot, you possibly can see two lead project guidelines. One is default and the opposite is a customized rule (Mule Project Rule) created for this weblog. Please observe that at a time just one project rule might be energetic.
Mule Project Rule
On this rule, leads are assigned to the homeowners primarily based on the situation for lead: nation, and after that e mail notifications are despatched to these homeowners because the ship e mail checkbox is true.
To know extra in regards to the salesforce project guidelines you possibly can refer right here.
Answer
AssignmentRuleHeader
To set off the project rule from MuleSoft, AssignmentRuleHeader
have to be specified within the salesforce connector for the desired project rule to be triggered. We will specify two forms of AssignmentRuleHeader
.
useDefaultRule
: This can be a boolean kind and it ought to be set to true. This triggers the default (energetic) project rule. If that is specified, don’t specify anassignmentRuleId
.assignmentRuleId
: On this kind, we will go the ID of a particular project rule to run for the case or lead. The lead or case project rule might be energetic or inactive. The Project rule ID might be fetched by querying theAssignmentRule
object. If that is specified, don’t specifyuseDefaultRule
.
EmailHeader
: To ship an e mail notification to the lead or case proprietor as part of the project rule, EmailHeader
with “triggerUserEmail
” kind set to 'true'
ought to be handed within the Salesforce connector.
Walkthrough
For the demo, we will likely be contemplating a use case the place leads are created in Salesforce utilizing MuleSoft. We will likely be utilizing the beforehand talked about ‘Mule Assignment Rule’
which assigns results in homeowners primarily based on the lead nation worth and sends e mail notifications.
Step 1
Add a mule circulation with the beneath connectors to create leads in Salesforce.
Step 2
Within the salesforceHeaders
variable set the AssignmentRuleHeader
and EmailHeader
with the beneath syntax:
%dw 2.0
output utility/java
---
{
"AssignmentRuleHeader": {
"useDefaultRule": true
},
"EmailHeader": {
"triggerUserEmail": true
}
}
Right here, we’re utilizing the useDefaultRule
choice which is able to set off the default energetic lead project rule.
In case your requirement is to set off a particular project rule, we will specify the assignmentRuleId
:
%dw 2.0
output utility/java
---
{
"AssignmentRuleHeader": {
"assignmentRuleId": "01Q5j000000p4xaEAA"
},
"EmailHeader": {
"triggerUserEmail": true
}
}
You will get the assignmentRuleId
by operating SOQL: SELECT id FROM AssignmentRule WHERE Title="Mule Assignment Rule"
Please observe that we have to go each the headers to set off the project rule and ship notifications. If the requirement is to solely set off the project and never ship an e mail, you possibly can skip the EmailHeader
. But when e mail notification is required it’s essential mandatorily add the EmailHeader
else it won’t ship an e mail even when the ship e mail checkbox is true within the project rule.
Step 3
Add the Salesforce transformation within the Remodel Message.
%dw 2.0
output utility/java
---
[
{
"FirstName": "John",
"LastName": "Doe",
"Company": "XYZ Company",
"Phone": "0123456789",
"Email": "john-doe@xyzcompany.com",
"Status": "Open - Not Contacted",
"Street": "1, Main Street",
"City": "New York City",
"State": "NY",
"Country": "US",
"PostalCode": "10001"
}
]
Please observe that we’re creating this lead with nation = ‘US’
which is able to fulfill the primary project rule situation and will assign this result in ‘Mule Max’
.
Step 4
Move the salesforceHeaders
variable within the headers part of the Salesforce connector.
Step 5
Run the appliance and set off the request.
Validation
- Lead Assigned: A lead is created in Salesforce and it’s assigned to
‘Mule Max’
as per the lead project rule.
- E mail Despatched: E mail is triggered to the lead proprietor as per the lead project rule.
E mail format might be completely different primarily based on the e-mail template used within the salesforce project rule.
Be aware: In case you are utilizing the Salesforce Sandbox setting, it could not set off the e-mail notification as a result of by default the ship e mail entry is disabled in Sandbox. To allow the ship e mail entry go to the e-mail deliverability setting within the Salesforce setup and alter the entry stage to All E mail.
Abstract
We’ve got coated easy methods to set off the salesforce lead project rule and ship e mail notifications to the lead homeowners when creating new leads from MuleSoft. The identical course of can be utilized for the case project guidelines.