Pages

Monday, August 11, 2014

Salesforce: Merge Field for User Object in Email Template

Email Alert in Workflow in Salesforce.com is simply awesome and easy to configure. The feature has been available since long time back. This blog is not going to discuss how to create Email Alert for Workflow, but you can read it through this documentation.

To make the email more meaningful, admin can add merge fields into the email subject or body. Rather than a static email "A case has been created", it is much meaningful to have email with message "A High priority case has been created - No: 001001" and email body contain more information, such as: Subject, Type, Priority, etc.

Admin just need to create an Email Template with merge fields from any object, from: Contact, Lead, including custom objects. Read this documentation.

Use Case: send email alert to a public group when a Salesforce user (not Chatter only user) has been deactivated.

1. Create Email Template
Subject: {!User.Region__c} Salesforce user has been deactivated - {!User.Name}
Body:
Hello,

Please note following user has been deactivated:
Name: {!User.Name}
Username - Region: {!User.Username} - {!User.Region__c}

Link: {!User.Link}

regards,
Salesforce.com


2. Create Email Alert
Make sure to select Public Group as Recipients and correct Email Template.


3. Create Worklow
Object = User
Evaluation Criteria = Evaluate the rule when a record is created, and every time it’s edited
Rule Criteria =
TEXT(UserType) = "Standard" && 
IsActive = False &&
PRIORVALUE(IsActive) = True

Add Email Alert above as immediate workflow actions and DONE!

But, wait a minute... something wrong with user information in the email received, merge field in email template have information of the user who has actually deactivate the user i.e. system admin and NOT the user which has been deactivated.

Good news in Summer '14 release, Salesforce introduce Workflow Target User Merge Fields for Email Templates, by changing merge field from !User to !Target_User, simply modified above email template:

Subject: {!Target_User.Region__c} Salesforce user has been deactivated - {!Target_User.Name}
Body:
Hello,

Please note user following user has been deactivate:
Name: {!Target_User.Name}
Username: {!Target_User.Username} - {!Target_User.Region__c}

Link: {!Target_User.Link__c}

regards,
Salesforce.com

If you notice last merge field above for link {!Target_User.Link__c}, it is a custom field, just change it to to {!Target_User.Link} will not work. Further search and test found that


This maybe a defect as currently it still Beta. So, the workaround, I create custom formula field in user object "https://xyz.salesforce.com/" & Id & "?noredirect=1" (change xyz to your Salesforce instance) - done !!


Reference:

2 comments:

  1. As you mentioned, the Detail Link didnt work back then. Unfortunately it still doesnt :/ Please UpVote this idea!
    Workflow Target User Fields UpGrade; do it for the Detail Link(and any others)! - https://success.salesforce.com/ideaView?id=0873A00000159OzQAI

    ReplyDelete