You need to sign in to do that
Don't have an account?
jameskCA
Help with sending template email with Merge fields from custom object
I'm not understanding how merge fields work when using templates sent via apex. Here is my current code:
What I'm still really confused about, even after reading the documentation, is what the setTargetObjectId and setWhatId actually do.
I need to merge several fields from our custom project object, so I was assuming that's what I would use the specific project record id as the setTargetObjectId, but I'm not sure if that's correct as everything I've read says the setTargetObjectId is who you're sending the email to, which in this case is our sales admin.
So, where / how do I set what the record is that I want to merge fields from, e.g. a specific project record. Thanks in advance.
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); Id templateId; String[] toAddresses = new String[]{'sales.admin@companydomain.com'}; email.setToAddresses(toAddresses); email.setTargetObjectId(p.Id); email.setTemplateId('00X11000000OO2B'); email.setorgWideEmailAddressId('0D2150000008TCX'); email.setSaveAsActivity(false); Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
What I'm still really confused about, even after reading the documentation, is what the setTargetObjectId and setWhatId actually do.
I need to merge several fields from our custom project object, so I was assuming that's what I would use the specific project record id as the setTargetObjectId, but I'm not sure if that's correct as everything I've read says the setTargetObjectId is who you're sending the email to, which in this case is our sales admin.
So, where / how do I set what the record is that I want to merge fields from, e.g. a specific project record. Thanks in advance.
I tried that but I'm getting an error now:
Any ideas?