Hi all,
I'm in the process of moving our Org from Classic to Lightning and I'm struggling with some custom Java Script buttons.
I have created custom Send Email buttons across different objects within Classic.
The button preloads the To field with the Main Contact from the Account or the Opportunity and it also preloads a template depending on the user.
I have run the Lightning Converter tool and it suggested creating a Lightning Component which I did but the new button doesn't preload the To field nor does it Preload the template.
Here is the code from Classic:
var templateId = '';
if('{!$User.Email}' == 'user1@email.es'){
templateId = '00X58000000MQDn';
}else if('{!$User.Email}' == 'user2@email.co.uk'){
templateId = '00X4H000000wnSw';
}else if('{!$User.Email}' == 'user3@email.es'){
templateId = '00X58000000MQ7T';
}else if('{!$User.Email}' == 'user4@email.co.uk'){
templateId = '00X58000000MhLm';
}else if('{!$User.Email}' == 'user5@.co.uk'){
templateId = '00X58000000MhJl';
}
window.open('/_ui/core/email/author/EmailAuthor?p2_lkid={!Opportunity.Main_ContactId__c}&p3_lkid={!Opportunity.Id}&template_id='+templateId+'&retURL={!Opportunity.Id}',"_blank","toolbar=yes,scrollbars=yes,resizable=yes,top=500,left=500,width=1000,height=900");
Here is the Lightning code:
COMPONENT
<aura:component extends="c:LCC_GenericLightningComponent" >
<aura:handler event="c:LCC_GenericApplicationEvent" action="{!c.execute}"/>
<aura:set attribute="partially" value="false"></aura:set>
<div style="height: 6rem;">
<div role="status" class="slds-spinner slds-spinner_large slds-spinner_brand">
<span class="slds-assistive-text">Loading</span>
<div class="slds-spinner__dot-a"></div>
<div class="slds-spinner__dot-b"></div>
</div>
</div>
</aura:component>
CONTROLLER
({
execute : function(component, event, helper) {
var templateId = '';
if (''+component.get('v.User.Email')+'' == 'user1@email.es')
{
templateId = '00X58000000MQDn';
}
else if (''+component.get('v.User.Email')+'' == 'user2@email.es')
{
templateId = '00X58000000MQDs';
}
else if (''+component.get('v.User.Email')+'' == 'user3@email.es')
{
templateId = '00X58000000MQ7T';
}
else if (''+component.get('v.User.Email')+'' == 'user4@email.co.uk')
{
templateId = '00X58000000MhLm';
}
else if (''+component.get('v.User.Email')+'' == 'user5@email.co.uk')
{
templateId = '00X58000000MhJl';
}
helper.gotoURL(component, '/_ui/core/email/author/EmailAuthor?p2_lkid='+component.get('v.sObjectInfo.Main_ContactId__c')+'&p3_lkid='+component.get('v.sObjectInfo.Id')+'&template_id=' + templateId + '&retURL='+component.get('v.sObjectInfo.Id')+'', '_blank');
$A.get("e.force:closeQuickAction").fire();
}
})
Questions:
1. Is there a standard functionality within Lighting to achieve what I am looking for?
2. Is a Lightning Component the best way to get the function I am looking for?
3. If the above is the best option, can anyone tell me where I am going wrong?
Thanks in advance,
Simon