I am very new to Salesforce (have no experince at all), so please excuse if I haven't explained the scenario correctly. I have "Send Email" button which has OnClick Javascript in Classic. The javascript code is as shown below. I am calling Page_Object which reference to the page (as Account or Contact or some custom object page) on which the user clicks the button


sforce.connection.sessionId = '{!$Api.Session_ID}'; 

var queryVal = sforce.connection.query("SELECT Id FROM Custom_Object__c WHERE (Custom_Object1.Name = 'val1' AND userId = '{!$User.Id}')"); 

var queryValrecord = queryVal.getArray("records"); 

var objectValue = "{!Page_Object.column1}"; 

if(queryValrecord.length === 1) { 
if(objectValue == 'some value'){
var str; 
var str = sforce.apex.execute("ApexClass", "ApexMethod",{ID:'{!Page_Object.Id}'}); 
if(str == 'success') 
else { 
alert('Warning message1'); 

else { 
alert('Warning message2'); 

Below is the Apex Method which is being called from apex.execute

   WebService static String SendEmail(String Id) {

        List<Messaging.SingleEmailMessage> email =  new List<Messaging.SingleEmailMessage>();
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
        String sendTo;

        Object obj = [SELECT Id,Name FROM Object Where Id=:Id LIMIT 1];

    sendTo = "[email protected]";

        email.setSenderDisplayName('Some Name');
        String body = obj.Name;

        email.saveAsActivity = false;
        return ('Email has been sent successfully');

While converting to Lightning component, I am sure we can use force:recordId to pass to controller method, but not sure how to handle the query and related conditions in the javascript while using component. How to access Page_Object.Column1 (which is nothing but some field value on that page) in Component? Can someone please guide me.

1 Answer 1


@getty use this tool Classic to lightning button converter.

You must log in to answer this question.

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