0

We have created a javascript based button.. As javascript buttons are not supported by lightning we need to look for any other solution. Thinking about VF and lightning. please suggest

{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 
var Suite = '{!Contract_Extract__c.Suite__c}'; 
var check = '{!Contract_Extract__c.Leadership_Notification_check__c}'; 
var TOV = '{!Contract_Extract__c.TOV__c}'; 
var RedLightReview = '{!Contract_Extract__c.Red_Light_Review__c}'; 
var ce = new sforce.SObject("Contract_Extract__C"); 
ce.id = "{!Contract_Extract__c.Id}"; 
if (( TOV >= 5000000000 || Suite != ' ' || RedLightReview != ' ' ) && check==0)
{ 
ce.Leadership_Notification_check__c = 1; 
result = sforce.connection.update([ce]); 
} 

we need to convert this code to work in both lex and classic ....

Please try to give suggestions ASAP on this

1

Try something similar to the below code Add you criteria inside the Send () method

  //Vf page
<apex:page standardController="Contact" extensions="SendEmailPageController">
<apex:form >
    <apex:commandButton action="{!send}"  value="Send Email" />
    <apex:commandButton action="{!cancel}" value="Cancel" />
</apex:form>
</apex:page>


//Controller

public class SendEmailPageController
{
public SendEmailPageController(ApexPages.StandardController controller)
{
}
public PageReference send()
{
    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
    String[] toAddresses = new String[] {'abc@yahoo.com'};
    mail.setToAddresses(toAddresses);
    mail.setBccSender(false);
    mail.setSubject('Subject');
    mail.setPlainTextBody('Test Message Body');
    Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
    for ( Messaging.SendEmailResult result : r )
    {
        if ( !r[0].isSuccess () )
        {
            System.debug ( result  );
        }
        else
        {
            ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.INFO, 'Email Sent Successfully' );
            ApexPages.addMessage(msg);
        }
    }
    return null;

}
}
|improve this answer|||||
  • few things also i need like add multiple email ids from custom field in CC and instead of plaintext we need to use the existing vf email template. If possible can you please help me with these as well...changes in the given code appreciated. – Reddy Mar 22 '17 at 8:10
  • @Reddy you can use this script mail.setTemplateId('00X30000001GLJj'); to set a specific template to send email and for multiple recipient "mail.setToAddresses(new String[] { 'TestUser@salesforce.com' ,'abc@test.com'});" you can try this – Samuel Robert Mar 22 '17 at 8:32
  • We don't want to hardcode the email ids. We need to pick the email ids that has been populated in the custom field. – Reddy Mar 22 '17 at 8:47
  • 1
    @Reddy then its simple just refer the Custom field name in place of the hardcoded Id's. – Samuel Robert Mar 22 '17 at 8:54
  • 1
    String[] toAddresses = new String[] {CsEmail}; Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); mail.setToAddresses(toAddresses); – Samuel Robert Mar 22 '17 at 8:57
0

If you need a button for both environments, try to do a JS button for classic and a Lightning Component with Lightning Quick Action interface for Lightning Experience & Salesforce1.

Create a Lightning component to display some info with a lightning:button that executes a Controller method that sends an email.

|improve this answer|||||
  • what if i use vf page only for both classic and lex? – Reddy Mar 26 '17 at 15:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.