I am on an Account page. I put a "Send email to External Agent" button. Behind this button there is a page connected to a controller:
public with sharing class emailToAgenteEsterno{
public Case c;
public Case c_1 {get;set;}
public EmailTemplate emailt1;
public Account acc;
public Agente_Esterno__c ae;
public Contact cont;
public emailToAgenteEsterno(ApexPages.StandardController controller){
c = ( Case )controller.getRecord();
c_1=[SELECT Id, Account.Agente_Esterno__c, Account.Agente_Esterno__r.Email__c, AccountId, CaseNumber
FROM Case
WHERE Id=:c.Id];
emailt1=[SELECT Id
FROM EmailTemplate
WHERE Name='Inoltro case per Agente Esterno' ];
cont = [SELECT Id, email
FROM Contact
WHERE AccountId =: c_1.AccountId
AND Agente_Esterno__c = true];
}
public pageReference returntopage(){
return new PageReference('/_ui/core/email/author/EmailAuthor?rtype=003&p2_lkid='+cont.id+'&p3_lkid='+c_1.Id+'&retURL='+c_1.Id+'&p5=&template_id='+emailt1.Id+'');
}
} In the method returntopage() there is a "way" in which Salesforce create a template putting the contact (cont.id) email in the TO of the mail. At its place I need to put another email (Account.Agente_Esterno__r.Email__c). I think I cannot use that URL because instead of the contact Id I should put the id of the Object containing the email I need (Agente_Esterno__c).
Summarizing: I have an email template and an email. Clicking the button "Send email to External Agent" I'd like to go on a page with that email template and with the field "to" filled with that email. What should I do?