function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Dave Wolfe 11Dave Wolfe 11 

Replace Javascrip Button

I'm looking for the simplest way to proceed.

We have a Javascript button in Salesforce classic. It is on a custom object called Addresses. We have customers with multiple addresses they move back and forth to and from, so we list the addresses in this object. There is a button on the records that they users push to populate the addresse in that record as the current address in the account.
Here is the JS button code.

{!REQUIRESCRIPT("/soap/ajax/19.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/19.0/apex.js")} 
var addr = "{!WV_Addresses__c.Id}"; 
var id = sforce.apex.execute("WV_AddressService","CopySingleAddress", {AddressID:addr}); 
window.alert("Address has been copied." );

This calls a Webservice program...


global class WV_AddressService {
  WebService static void CopySingleAddress(ID AddressID){
    WV_Addresses__c addr = [Select w.Worker_Profile__c, w.Type__c, w.SystemModstamp, w.Street__c, w.State__c, w.Postal_Code__c, w.OwnerId, w.Name, w.LastModifiedDate, w.LastModifiedById, w.IsDeleted, w.Id, w.Full_Address__c, w.Current__c, w.CreatedDate, w.CreatedById, w.Country__c, w.City__c, w.Active_On_Date__c, w.Mobile_Phone__c From WV_Addresses__c w WHERE Id = : AddressID];
    
    WV_AddressController.CopyToAccount(addr);
  }
}

Which calls the WV_AddressController.

Obviously the button does not work in Lightning, but the rest of the code works wonderfully and is a big timesaver for our users.All I ned to do is to replace the button that calls the Webservice with the 2 lines of script that the javascript button is currently calling. What is the easiest way to get than done?

Thanks!
 
Best Answer chosen by Dave Wolfe 11
Ravi Dutt SharmaRavi Dutt Sharma
Hi Dave,

You need to create a quick action and call the webservice from the quickaction. More details in link below:

https://www.mstsolutions.com/technical/launching-lightning-component-as-quick-action/

All Answers

Ravi Dutt SharmaRavi Dutt Sharma
Hi Dave,

You need to create a quick action and call the webservice from the quickaction. More details in link below:

https://www.mstsolutions.com/technical/launching-lightning-component-as-quick-action/
This was selected as the best answer
Dave Wolfe 11Dave Wolfe 11
Hi Ravi, 

    Thank you. That is what I needed to know!