You need to sign in to do that
Don't have an account?
ssousan
Can i use a field from a custom object in an Email Templates?
I'm writing an Email template that includes merged fields,
When I add an account field it works fine,
But when I try to add a field from a custom object it does not work,
Do Email templates accept fields from custom objects?
Thanks
Note that, as was said earlier, sending emails to users doesn't allow sending by template. Instead, you should probably create a contact record for each user, then send the email to the contact instead.
All Answers
If you're doing this in Apex Code, the same basic rule applies; you have to set the What Id for the email message (via EmailMessage.setWhatId) to the custom object's record ID.
Visualforce email templates can refer to indirectly related records.
myCustomObject__c.myFieldName__c or
myCustomObject__c.Link ( for the detail link to that custom record)
This is what i used:
myCustomObject__c.myFieldName__c
And when i send the email i get blank text in that location
Best
So this is how i set it up:
Inquery__c inquery = trigger.new[0];
String[] toAddresses = new String[] {inquery.email__c};
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setTargetObjectId(inquery.OwnerID);
mail.setWhatId(inquery.OwnerID);
mail.setSenderDisplayName('Salesforce Support');
mail.setUseSignature(false);
mail.setBccSender(false);
mail.setSaveAsActivity(false);
EmailTemplate et=[Select id from EmailTemplate where DeveloperName=:'Invitation_to_register_for_Training'];
mail.setTemplateId(et.id);
Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
but im getting the following error:
Error:Apex trigger send_notification caused an unexpected exception, contact your administrator: send_notification: execution of AfterUpdate caused by: System.EmailException: SendEmail failed. First exception on row 0; first error: INVALID_ID_FIELD, WhatId is not available for sending emails to UserIds.: []: Trigger.send_notification:
Do you know why?
Thanks
What Id only works for contacts not for user, comment it out, and it should work
Yes i just added that line of code,
Because i was trying to follow sfdcfox instructions,
But i guess im not doing the correct thing,
Best
is that a single or a multiple email just wondering as you have [] after the new command
Its a single Email
Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
I have in my codes always only
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
Messaging.sendEmail(mail);
I get an error when i write:
Messaging.sendEmail(mail);
that says:
Error: Compile Error: Method does not exist or incorrect signature: Messaging.sendEmail(Messaging.SingleEmailMessage) at :
But the way i have written it works fine.
You need to have a List<Messaging.SingleEmailMessage>, not just a single message.
Not sure exactly how to do that,
Could you give me an example,
Thanks
Note that, as was said earlier, sending emails to users doesn't allow sending by template. Instead, you should probably create a contact record for each user, then send the email to the contact instead.