2

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?

1
  • You are basically doing URL hacking, you will have to find itself it that URL support custom object or not.
    – Ashwani
    Commented Jun 23, 2015 at 9:32

1 Answer 1

1

You can get the email you need to send to as a string with SOQL and then use it in the URL "p24" parameter that controls the "additional to" field.

I.e. https://eu5.salesforce.com/_ui/core/email/author/[email protected]

2
  • I know that I shoudn't use the comment line to say thanks but.... THANKS THANKS THANKS!!! Commented Jun 23, 2015 at 10:32
  • 2
    @AndreaIanni௫ Here is a complete list of parameters which can be sent through the URL p3_lkid – Related To retURL – Return URL if cancel is pressed p2_lkid – To (Contact or Lead ID) p4 – CC p5 – BCC p6 – Subject p23- Email Body p24 – Additional To template_id – Salesforce Email Template ID Source - salesforceben.com/salesforce-email-url-hack-tutorial
    – Saroj Bera
    Commented Jun 23, 2015 at 10:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .