+ Start a Discussion
Dipika RajputDipika Rajput 

AJAX toolkit(Connection.js) is not working in lightning component.

hi  Dipika Rajput 
can you share yoru component code, where you try to using AJAX toolkit 
thanks sfdcmonkey.com
Dipika RajputDipika Rajput
<aura:component implements="force:lightningQuickAction,force:hasRecordId">
    <aura:attribute name="recordId" type="Id" />
    <ltng:require scripts="{!$Resource.connectionJs}" afterScriptsLoaded="{!c.doInit}" />
    <!--<ltng:require scripts="{!$Resource.ApexJs}" afterScriptsLoaded="{!c.doInit}"/> -->
Dipika RajputDipika Rajput

->Yes, my doinit function is getting called upto this alert(sforce.connection.sessionId).After this part I am getting error for below part which is in bold.


    doInit : function(component, event, helper) {
        alert('into controller...'+component.get("v.recordId"));
        var accountTypeCheck = true; 
        var accountNameCheck = true; 
        var accountId = component.get("v.recordId");
        var standardField = []; 
        var customFields = []; 
        var mapCustomSetting = {}; 
        // getting custom setting value 
        var recordsofCustomSetting = sforce.connection.query("Select Name,FieldApiName__c,SetPreferredAddressType__c From FieldNameMapping__c where ObjectName__c = 'Account'"); 


->This is the error which I am getting on click of action which is written in doinit function:-

Uncaught Action failed: c:AccountPushScriptApproach$controller$doInit [Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'https://hircrm-dev-ed.lightning.force.com/services/Soap/u/39.0'.]
throws at https://hircrm-dev-ed.lightning.force.com/auraFW/javascript/uUttwQR-pk5rKvOBHB6bAQ/aura_prod.js:2:15

as per my understanding this connection.js library not working with lightning component.
here is the refrence link for it
hopes it helps you
thanks let me inform if it helps you
Connection.js is the Soap API libray. It requires to have a valid sesison id defined through sforce.connection.sessionId
Lightning session of the user (such as {!GETSESSIONID()} )cannot be used for this purpose as by design, Lightning sessions will never be available for Api usage. Doug Chasman has already explained this in various forums.
Even if you could have a tricky workaround to get a valid session for API usage, you could probably face CORS issues as the Soap API is not CORS enabled and the end point is not the same as the lightning domain.
You should better access Salesforce from your server component controller and push back the data to the client controller.