What I'm trying to do, is have a User Login and be redirected to a non-Salesforce page.

Currently, I am attempting to do this via SOAP as I can't find another way to do it?

I am getting a "Attempt to de-reference a null object" right after the .getChildElement('result','urn:partner.soap.sforce.com'). I'm trying a few different routes, but this is the closest I've gotten so far, so hoping that maybe I'm close?

I've got this in a method

public void TestLoginController() {

and it is being referenced a VFP button via {!TestLoginController}... when I press that button I'm getting:

HttpRequest request = new HttpRequest();
    request.setHeader('Content-Type', 'text/xml;charset=UTF-8');
    request.setHeader('SOAPAction', '""');
    request.setBody('<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"><Header/><Body><login xmlns="urn:partner.soap.sforce.com"><username>' + USERNAME + '</username><password>' + PASSWORD + '</password></login></Body></Envelope>');

    Dom.XmlNode resultElmt = (new Http()).send(request).getBodyDocument().getRootElement()

    **---error happening----**

    final String SERVER_URL = resultElmt.getChildElement('serverUrl','urn:partner.soap.sforce.com').getText().split('/services')[0];
    final String SESSION_ID = resultElmt.getChildElement('sessionId','urn:partner.soap.sforce.com').getText();
  • 1
    Can you debug your "resultElmt" and add it in question? Jan 27, 2016 at 5:13
  • Having issues getting it to debug that right now, its not showing up in the log. I am getting this: CALLOUT_RESPONSE [42]|System.HttpResponse[Status=Server Error, StatusCode=500] Jan 27, 2016 at 5:35
  • 2
    You are getting this error because your callout is not successful. I would recommend to use SOAPUI (soapui.org) to capture the syntax and then try it here. Use Salesforce partner WSDL to mock the authentication calls. Jan 27, 2016 at 5:38

1 Answer 1


Status Code of 500 indicates that the call is not made successfully. Something has went wrong. Just print response.getBody() in the debug log (System.debug()) and see the content returned for the callout. Based on that start to debug the issue

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .