+ Start a Discussion
Rung41Rung41 

Custom Email button to select template based on user

Right now I have a custom email button that calls and specific email template. Is there any way to use the same button but call a different template from either a a custom object on the users record?

Baiscally if User's showroom = this, then template = this

This is the code for the custom email button I currently have:

https://cs3.salesforce.com/_ui/core/email/author/EmailAuthor? 
&p3_lkid={!Opportunity.Id} 
&p3={!Opportunity.Name} 
&rtype=003 
& 
IF(AND({!ISPICKVAL( $User.Showroom__c , "Houston")}) , template_id = 00X30000001ARUA), 
IF(AND({!ISPICKVAL( $User.Showroom__c , "Lake Forest")}), template_id = 00X30000001AGI9), 
&p26={!$User.Email} 
&p24={!Opportunity.Renters_Email__c} 
&retURL=/{!Opportunity.Id} 
&saveURL=/{!Opportunity.Id}

Best Answer chosen by Admin (Salesforce Developers) 
Rung41Rung41

I used a Case statment to call the template. Got a some help from

Anthony Victorio

(https://sites.secure.force.com/success/profile?u=00530000003TQ7zAAG)

 

&template_id={!CASE(User.Showroom__c , 
'Lake Forest','00X30000001AGI9', 
'Houston','00X30000001AGWW', 
'00X30000001A3Or')}

All Answers

SFDCMattSFDCMatt

Give this a shot, will require some tweaking, but should get you started:

 

{!REQUIRESCRIPT("/soap/ajax/18.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/18.0/apex.js")} 

//The lines below will restrict the feature to a certain profile, current Admins 
if('{!$User.ProfileId}' == '00e000000063Pvr') { 
  //one URL goes here
} 
else{ //the other URL would go here, something like:
window.open('/email/author/emailauthor.jsp?retURL=/{!Lab_Projects__c.Id}&rtype=003&template_id=00X00000006qPJx&p2_lkid='+ContactIds[0].Contact_Name__c+'&p3_lkid='+IdsToEmail[subIndex]);  
} 

 

SFDCMattSFDCMatt

Ignore that first line of comments, that was my original code, intended to remove that...

Rung41Rung41

Thank you. I'll give it a shot and let you know how it turns out. Thanks again!

Rung41Rung41

I used a Case statment to call the template. Got a some help from

Anthony Victorio

(https://sites.secure.force.com/success/profile?u=00530000003TQ7zAAG)

 

&template_id={!CASE(User.Showroom__c , 
'Lake Forest','00X30000001AGI9', 
'Houston','00X30000001AGWW', 
'00X30000001A3Or')}

This was selected as the best answer