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
Abilash Kosigi 8Abilash Kosigi 8 

Assigning SessionId issue while using SOAP API in Apex


First of all, Wish you a very happy new year. :)

I have an issue in assigning Session id while I am trying to login to another salesforce org using SOAP API. Here is the code.

partnerSoapSforceCom.Soap sp = new partnerSoapSforceCom.Soap();

String username = 'username';
String password = 'password';

partnerSoapSforceCom.LoginResult loginResult = sp.login(username, password);

soapSforceCom200608Apex.Apex apexWebSvc = new soapSforceCom200608Apex.Apex();
soapSforceCom200608Apex.SessionHeader_element ses = new soapSforceCom200608Apex.SessionHeader_element();
ses.SessionId = loginResult.sessionId;

apexWebSvc.timeout_x = 120000;
apexWebSvc.SessionHeader = sessionHeader;

I see no error in the code. But dev console throws unexpected token '=' error for every statement from ses.SessionId = loginResult.sessionId; statement.

Can anyone please let me know where I am missing the point.

Note. All WSDLs and apex soap api related classes are successfully generated without any compilation erros.

After getting the ses instance, shouldn't you be using that in apexWebSvc.SessionHeader = ses; ?