I have an email template that includes a commandLink. This utility method is used to send the email.
public static Boolean sendEmailTemplate(String tNm, Id toId, Id wId) {
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
EmailTemplate et = [SELECT id from emailtemplate where name= :tNm];
mail.setTemplateId(et.Id);
mail.setSaveAsActivity(false);
mail.setTargetObjectId(toId);
mail.setWhatId(wId);
// Use Organization Wide Address
for(OrgWideEmailAddress owa : [select id, Address from OrgWideEmailAddress]) {
if(owa.Address.contains('noreply')) {
mail.setOrgWideEmailAddressId(owa.id);
}
}
try {
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
} catch (Exception e) {
System.debug(logginglevel.error,e);
return false;
}
return true;
}
The email template includes a commandlink. When I execute this from anon apex (subbing in IDs for the params) it works like a charm. However, when I execute it from my application, the email is sent, but the link doesn't work. In looking at the logs, the log from the anon apex has a normal href tag:
<
a href="www.salesforce.com">
but in the application log it is resolved as
<a href="javascript:srcUp('www.salesforce.com%3Fisdtp%3Dvw');">
Why?
a
tag instead ofapex:commandlink
to force it to resolve to a url.