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
Nikhil Khandare 1Nikhil Khandare 1 

How to get session Id

Hi All,

I want to insert account record from one SF orgnisation to another SF org. In destination orgnaisation i have created below webservice method.
global class testSOAPAccInsert{

    webservice static Id insertAcc(String name)
    {
        Account acc = new Account();
        acc.Name = name;
        insert acc;
        return acc.Id;
    }
}

I generated wsdl from it and created class using wsdl in source orgnisation. However, when i tried to invoke this method from class generated using wsdl i am getting illegeal session id error. 

How would i get session id or how can i impelment login method in my global class. Please help.

Thanks,
Nikhil 
Koen (BvD)Koen (BvD)
I never tried, but I would not expect sessionIds to be interchangeable between orgs even if you would by coincidense have the same userIds. Also because this webservice call does not go through your browser, your current login that you would do in the browser in the second org won't have any effect
Your only option will be to login with username / password from within your static webservice code. One way would be to use the api of salesforce because there is a login method. When searching for a login method in apex code, I found this thread that seems to be exactly what you are looking for
https://gist.github.com/richardvanhook/1245068