->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"); console.log('===accountId==='+accountId); var standardField = []; var customFields = []; var mapCustomSetting = {}; //sforce.connection.sessionId='{!GETSESSIONID()}'; alert(sforce.connection.sessionId); // 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 sforce.Transport.send()@/resource/1487582730000/connectionJs:597:25 sforce.SoapTransport.send()@/resource/1487582730000/connectionJs:1015:19 sforce.Connection._invoke()@/resource/1487582730000/connectionJs:1802:22 sforce.Connection.invoke()@/resource/1487582730000/connectionJs:1741:17 sforce.Connection.query()@/resource/1487582730000/connectionJs:1396:17 doInit()@components/c/AccountPushScriptApproach.js:21:56
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.
can you share yoru component code, where you try to using AJAX toolkit
thanks sfdcmonkey.com
<aura:attribute name="recordId" type="Id" />
<ltng:require scripts="{!$Resource.connectionJs}" afterScriptsLoaded="{!c.doInit}" />
<!--<ltng:require scripts="{!$Resource.ApexJs}" afterScriptsLoaded="{!c.doInit}"/> -->
"{!$Resource.connectionJs}"
</aura:component>
->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");
console.log('===accountId==='+accountId);
var standardField = [];
var customFields = [];
var mapCustomSetting = {};
//sforce.connection.sessionId='{!GETSESSIONID()}';
alert(sforce.connection.sessionId);
// 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
sforce.Transport.send()@/resource/1487582730000/connectionJs:597:25
sforce.SoapTransport.send()@/resource/1487582730000/connectionJs:1015:19
sforce.Connection._invoke()@/resource/1487582730000/connectionJs:1802:22
sforce.Connection.invoke()@/resource/1487582730000/connectionJs:1741:17
sforce.Connection.query()@/resource/1487582730000/connectionJs:1396:17
doInit()@components/c/AccountPushScriptApproach.js:21:56
here is the refrence link for it
http://salesforce.stackexchange.com/questions/55306/how-to-call-a-salesforce-rest-url-from-lightning-component
hopes it helps you
thanks let me inform if it helps you
thanks
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.