Use case:

Converting JS button to lightning quick action. Button below


var w = window; 
var html_doc = w.document.getElementsByTagName('head')[0]; 
var js = w.document.createElement('script');


var accName = '{!JSENCODE(Account.Name)}';

var url = '/{!$Setup.General_Settings__c.Change_Request_Object_Prefix__c}/e?RecordType={!$Setup.General_Settings__c.Quick_Update_CR_Record_Type_ID__c}&retURL=%2F{!Account.Id}&CF{!$Setup.General_Settings__c.Change_Request_Account_Ctl_Id__c}=' + accName + '&CF{!$Setup.General_Settings__c.Change_Request_Account_Ctl_Id__c}_lkid={!Account.Id}';

var openSubtab = function openSubtab(result) {
w.sforce.console.openSubtab(result.id , url, true, 'Create CR', null, function() {}, 'Create CR');
js.onload= function() { 
if(w.sforce.console.isInConsole() == false) { w.open(url,'_blank'); } 
else { w.sforce.console.getEnclosingPrimaryTabId(openSubtab);} 

Now this would be a pretty easy rewrite, sets vars of the account.name and current record Id...

But after googling i'm getting mixed info. Some info is "some global variables are accessible in components" and "none are accessible". So that being the case would a call to an apex handler be appropriate?

Basically i need to create an apex method that returns the following....

    General_Settings__c var1 = new General_Settings__c.getvalues('Change_Request_Object_Prefix__c'); 

 General_Settings__c var2 = new General_Settings__c.getvalues('Quick_Update_CR_Record_Type_ID__c'); 

 General_Settings__c var3 = new General_Settings__c.getvalues('Change_Request_Account_Ctl_Id__c');

but then how return var1,var2,var3. Will it pass the strings raw data which is just id's we use (think kljhdt82y3) or will i be able to do.

var state = response.getState();
    if (state == "SUCCESS") {
        var var1 = response.getReturnValue(var1);

basically i need three variables from an apex class passed to my JS controller so i can create the URL that would be needed.

Can a return even do return var1, var2, var3 (i'm guessing not) or will i have to return a list? Would it be easier just to call on three separate apex methods and get those individually return values?

  • This JS button seems like a prime candidate for replacing with a New Record Quick Action with Prefined Field values, rather than replacing with custom code. This button is using old URL hacking techniques that just aren't necessary or recommended in Lightning - you would absolutely not want to "create the URL" here - it wouldn't even work in Lightning. The Object Prefix and Change Request Account CTL Id are definitely irrelevant and not something you'd use in rebuilding this solution for Lightning. Apr 25, 2019 at 20:47

1 Answer 1


There are some "global" variables, as outlined in Value Providers, but $Setup is not currently one of them. You could just return all the values from your custom setting and then decide which you'd like to use:

@AuraEnabled public static General_Settings__c[] getGeneralSettings() {
  return General_Settings__c.getAll().values();

Other alternatives are possible as well, but this is probably the most straightforward approach.

You must log in to answer this question.

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