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
Anshuma YadavAnshuma Yadav 

Using below code I am not getting getting response, even not getting any error.

I am eliminating dependency of apex from LWC component and want to get custom objects from salesforce org to migrate custom objects into another org using SOAP callout in LWC.

var myHeaders = new Headers();
myHeaders.append("SOAPAction", " login");
myHeaders.append("Content-Type", " text/xml; charset=utf-8");
myHeaders.append("Cookie", "BrowserId= ; CookieConsentPolicy=0:0; LSKey-c$CookieConsentPolicy=0:0");
var raw = '<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:urn=\"urn:enterprise.soap.sforce.com\">'
          +'<soapenv:Body>'
          +'<urn:login>'
          +'<urn:username>myusername</urn:username>'
          +'<urn:password>mypassword</urn:password>'
          +'</urn:login>'
          +'</soapenv:Body>'
          +'</soapenv:Envelope>';
var requestOptions = {
method: 'POST',
headers: myHeaders,
mode:'no-cors',
body: raw,
redirect: 'follow'
};
fetch("https://login.salesforce.com/services/Soap/c/57.0", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));

 

SubratSubrat (Salesforce Developers) 
Hello Anshuman ,

I can suggest some suggestions to help you troubleshoot the problem:

Verify the SOAP endpoint: Make sure the endpoint URL you're using is correct and valid. The URL you provided, "https://login.salesforce.com/services/Soap/c/57.0", seems to be the correct endpoint for the Salesforce API version 57.0. However, double-check if this is the correct URL for your specific Salesforce organization.

Remove "mode: 'no-cors'": The mode: 'no-cors' option prevents the browser from throwing CORS (Cross-Origin Resource Sharing) errors but also prevents you from accessing the response data. Remove this option to see if any errors or response data are returned.

Check the SOAP request payload: Make sure the SOAP envelope and request payload are formed correctly. Ensure that the namespace prefixes (soapenv and urn) match the correct SOAP namespaces used by the Salesforce API.

Debug the response: Instead of using console.log(result) to log the response, try using console.log(result.body) or console.log(result.text()) to see the actual response data. Additionally, log the entire response object (console.log(response)) to check for any HTTP status codes or error messages.

Use a tool like Postman: To validate your SOAP request separately, you can use tools like Postman or SOAP UI to send the SOAP request and verify the response. This can help isolate any issues specific to your code.
Check for any browser errors: Open the browser developer console (e.g., Chrome DevTools) and check for any error messages or network requests related to your SOAP callout. This can provide additional information about what might be going wrong.


Hope this helps !
Thank you.