0

Connection.js and apex.js are not working in Lightning Component. My code is as follow.

Component Code (RTBasedPicklist):

<aura:component controller="RTBasedPickListController">
    <ltng:require scripts="{!join(',' , '/soap/ajax/40.0/connection.js','/soap/ajax/40.0/apex.js')}" afterScriptsLoaded="{!c.doInit}"/>    
</aura:component>

Controller Code:

({
    doInit : function(component, event, helper) {
        sforce.connection.sessionId='{!GETSESSIONID()}';
        console.log('halo');
        var result = sforce.connection.describeLayout('Opportunity');
        console.log((result));
    }
})

This results as:

Error : This page has an error. You might just need to refresh it. Action failed: c:RTBasedPicklist$controller$doInit [Failed to execute 'send' on 'XMLHttpRequest': Failed to load '{baseurl}/services/Soap/u/40.0'.] Failing descriptor: {c:RTBasedPicklist$controller$doInit}

Nihar
  • 1,182
  • 2
  • 13
  • 30
Kritik
  • 266
  • 3
  • 11
  • 38
  • If I am not wrong then connection.js library not working with lightning component. here is the refrence link for it http://salesforce.stackexchange.com/questions/55306/how-to-call-a-salesforce-rest-url-from-lightning-component – cloudy-ritz Aug 03 '17 at 09:40
  • The error states that the page is unable to execute XMLHttpRequest object, without which the script won't be able to interact with the sever. You cannot use Ajax toolkit in Salesforce Lightning and the bad thing is that they have perhaps not documented this in the Ajax toolkit dev guide. If you want to call the action from within a script, try using Javascript remoting or Javascript remote objects. Both these options also give you the liberty to create an apex class and perform complicated tasks. Otherwise, using an AuraEnabled class is a good option. – the_phantom Aug 03 '17 at 10:03

1 Answers1

3

Connection.js and apex.js are not available in Lightning Components. You'll have to create an Apex Class that returns what you want and call a server side action from your component.

Fabien Taillon
  • 8,605
  • 2
  • 38
  • 58
  • My use case: https://salesforce.stackexchange.com/questions/187090/fetching-picklist-value-based-on-record-type-in-lightning-component – Kritik Aug 03 '17 at 10:21