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
Robert Davis 16Robert Davis 16 

Javascript Button to Go to outside URL

I have a Javascript button in Lightning that needs to go out to SpringCM and pulls a form up that our users complete, it uses fields from the Opportunity that it pass through the URL. I am desperately trying to figure out how to do this and have tried the Trailhead Module: Lightning Alternatives to JavaScript Buttons and either it does not explain for my example or I am unable to understand. Can someone point me to any other solutions?

The Button is below:

//Should not have to change this at all 
function getEOSInfo(objectid,objecttype,callback) { 

var baseUrl = "{!$Api.Partner_Server_URL_260}".substring(0, "{!$Api.Partner_Server_URL_260}".indexOf("/services")); 
var url = baseUrl +"/services/apexrest/SpringCMEos/eosinfo?objecttype="+objecttype+"&objectid="+objectid; 
var authkey = "Bearer {!$Api.Session_ID}"; 

url : url, 
requestHeaders: {"Authorization":authkey,"Accept":"application/json"}, 
onSuccess : function(response) { 
var eosInfoResponse = JSON.parse(response); 

//Here you write your own code, this is a simple call 
var objectid = "{!Opportunity.Id}"; 
var objecttype = "Opportunity"; 


var formuid = "8be07531-XXXX-e611-XXXX-6c3be5a7XXXX"; 
var url = "" + formuid + "&SFFTE={!Opportunity.FTEs__c}&SFIND={!Account.Industry}&SFPSD={!Opportunity.ProgramStartDate__c}&SFID=" + eosInfo.SFId + "&SFNAME={!Opportunity.Name}&SFWF=ABC&SFCAFTYPE=CAAF&SFTYPE=Salesforce.Opportunity&SFPATH=" + eosInfo.FolderPath + "&ru=%2Fatlas%2Fbpm%2FWorkList.aspx";; 


Your help is greatly appreciated.
Best Answer chosen by Robert Davis 16
Sandeep WaliaSandeep Walia
Hi Robert, Please note that does not always work in Salesforce Lightning.
Reply in case you face any challenge. 

Hope this helps,


All Answers

Sandeep WaliaSandeep Walia
Hi Robert, Please note that does not always work in Salesforce Lightning.
Reply in case you face any challenge. 

Hope this helps,

This was selected as the best answer
Robert Davis 16Robert Davis 16

Thank you, I will start to work on it now. I do appreciate your help.

Robert Davis 16Robert Davis 16
Sandeep, and others have helped so much in my quest to getting something to work. The following is not perfect and I am certain there are better ways, but I hope this will help someone else.

Lightning Component Code and the Apex Controller - 2017 / 08 / 03


<aura:component implements="force:lightningQuickAction,force:appHostable,flexipage:availableForAllPageTypes,force:hasRecordId" access="global" 
    <aura:attribute name="recordId" type="Id" />
    <div id="aura-page">
        <div class="container" style="background-color:#f2f2f7">
            <ui:button class="btn" label="CAF Form" press="{!c.navigate}"/>  SpringCM Contract Amendment Form Button 

Apex Controller - SpringCMApexController.apxc
public class SpringCMApexController {

    public static Opportunity getOpportunity(ID opportunityId){
        if(opportunityId == null) {
            return null;
        List<Opportunity> opps = [SELECT id, 
                                         Opportunity.Account.Industry ,
                                         Opportunity.TotalNumberofSeats__c ,
                                         Opportunity.CAPEX_Required__c ,
                                         Opportunity.Amount ,
                                         Opportunity.ProgramStartDate__c ,
                                         Opportunity.Account.Name ,
                                  FROM Opportunity
                                  WHERE Id =: opportunityId];
            return opps[0];
        return null;

    navigate : function(component, event, helper) {

    navigate : function(component) {
        var action = component.get("c.getOpportunity");
        var idOpp = component.get("v.recordId");
            action.setParams({opportunityId: idOpp});
            // Create a callback that is executed after 
            // the server-side action returns
            action.setCallback(this, function(response) {
                var state = response.getState();
                if (state === "SUCCESS") {
                    var opp = response.getReturnValue();
                    /* Here you can access like opp.Id, opp.FTEs__c, opp.Account.Industry and form the URL */
                    var fullTimeEmployees = opp.FTEs__c;
                    var industry = opp.Account.Industry;
                    var programStartDate = $A.localizationService.formatDate(Date(opp.ProgramStartDate__c),"MM/DD/YYYY");  
                    var opportunityId = opp.Id;
                    var opportunityName = opp.Name;                    
                    var filePath = '/Accounts/'+ opp.Account.Name + '/Opportunities/&ru=%2Fatlas%2Fbpm%2FWorkList.aspx'
                    var partOneURL = '';
                    var partTwoURL = 'aid=7284';
                    var formUid = '8be07531-d9b0-e611-bb8d-6c3be5a75f4d';
                    var finalURL = partOneURL + partTwoURL 
                    var finalURL = finalURL + '&FormUid=' + formUid;
                    var finalURL = finalURL + '&SFFTE=' + fullTimeEmployees;
                    var finalURL = finalURL + '&SFIND=' + industry;
                    var finalURL = finalURL + '&SFPSD=' + programStartDate;
                    var finalURL = finalURL + '&SFID=' + opp.Id;
                    var finalURL = finalURL + '&SFNAME=' + opportunityName;
                    var finalURL = finalURL + '&SFWF=ABC';
                    var finalURL = finalURL + '&SFCAFTYPE=CAAF';
                    var finalURL = finalURL + '&SFTYPE=Salesforce.Opportunity';
                    var finalURL = finalURL + '&SFPATH=' + filePath;
                    var urlEvent=$A.get("e.force:navigateToURL");
                    urlEvent.setParams({"url": finalURL});
                else if (state === "ERROR") {
                    var errors = response.getError();
                    if (errors) {
                        if (errors[0] && errors[0].message) {
                            console.log("Error message: " + 
                    } else {
                        console.log("Unknown error");

            // optionally set storable, abortable, background flag here

            // A client-side action could cause multiple events, 
            // which could trigger other events and 
            // other server-side action calls.
            // $A.enqueueAction adds the server-side action to the queue.
            console.log('===Record Id is not present====');

#JS_Alternative #SpringCM