Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
in Salesforce by (11.9k points)

i have to send an email to a user in salesforce using email template.this template contain merge field type of custom object.

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.saveAsActivity = false;

i read in documentation If you specify a contact for the targetObjectId field, you can specify a whatId as well. This helps to further ensure that merge fields in the template contain the correct data. The value must be one of the following types: Account Asset Campaign Case Contract Opportunity Order Product Solution Custom

but if we are sending email to a user not to contact then how to assign a custom object for merge field type in custom objects as in the above code

1 Answer

0 votes
by (32.1k points)

Not exactly sure if this is possible as it depends on the relationships between your custom object and your users. In a custom formula field on your User object use the following code:


Then your template can be changed into a User template and the merge fields would be the formula that actually pointed to your custom object instance.

To learn in-depth about Workflow in Salesforce, sign up for an industry based Salesforce training online.

Browse Categories