I am using enterprise wsdl to login and get session id. as I have verified in login history, Its logged in successfully. But it throws the error when it invokes the another sfdc webservice from future call.
caused by: System.CalloutException: Web service callout failed: WebService returned a SOAP Fault: INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session. Session not found, missing session key: 00DS00000009UqA!AQIAQKOw6N5keVHqAYpYBcmUV_8jm_M0o2r.zUuE1AuH3hiirb4jG65iyOewJNwEIAkCwRALXeu5ppoz07bVuY.XXXXXX
This is expected, it can happen if the session has expired and swept away, or if the user logs out, or if its just someone trying to hack in. faultcode=sf:INVALID_SESSION_ID faultactor=
I have made the end point domain unique.what could be the cause of this issue?
My Code:
@Future(callout=true)
public static void addPDFAttachment(List<Id> lstId){
enterpriseSoapSforceCom.LoginResult lr = new enterpriseSoapSforceCom.LoginResult();
enterpriseSoapSforceCom.Soap sp = new enterpriseSoapSforceCom.Soap();
sp.timeout_x = 60000;
lr = sp.login(username, password);
SoapSforceAttachAPI.AttachPDFforArchiving objAttachPDFInstance = new SoapSforceAttachAPI.AttachPDFforArchiving();
objAttachPDFInstance.timeout_x=120000;
SoapSforceAttachAPI.SessionHeader_element sessionHeader = new SoapSforceAttachAPI.SessionHeader_element();
sessionHeader.sessionId = lr.sessionId;
objAttachPDFInstance.SessionHeader = new SoapSforceAttachAPI.SessionHeader_element();
objAttachPDFInstance.SessionHeader.sessionId = lr.sessionId;
objAttachPDFInstance.attachPDF(lstId, '', 'No');
}