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
arigelaarigela 

Write test method for session Id

Hi,

Can you please help any one to test the below code.
Note:  I am creating test user, and test mock callout in my test class, but getting null pointer exception on when getting sessionId.

 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()
        .getChildElement('Body','http://schemas.xmlsoap.org/soap/envelope/')
        .getChildElement('loginResponse','urn:partner.soap.sforce.com')
        .getChildElement('result','urn:partner.soap.sforce.com');
       
        String sessionId = resultElmt.getChildElement('sessionId','urn:partner.soap.sforce.com').getText();

Thanks
Venkat
Martijn SchwarzerMartijn Schwarzer
Hi Venkat,

Can you post the code of the mock callout class? It's hard to see what's going wrong without that code and especially the returned xml message.
Thanks.

Regards,
Martijn Schwärzer