You need to sign in to do that
Don't have an account?

How to get server url and session id in apex class - i don't want to use apex page to get that one
How to get server url and session id in apex class - i can not use visual force page to get that one.
your help is appreciated..
Not sure about server URL but you can get the session ID by
String sessionID = UserInfo.getSessionId();
I am having the same problem.
Is using UserInfo.getSessionId() really equivalent to $!Api.Session_ID in the same Visualforce page context?
When I look at the output results of {$!Api.Session_ID} and {$!SessionId} merge variables in the same URL string (where {$!SessionId} is the result of an Apex controller get method of UserInfo.getSessionId) the values start out similarly for the first 25 characters or so, then diverge completely.
Why are the different?
Should I care that they are different?
Is using the Apex UserInfo.getSessionId() value "valid & correct enough" for my application to use to access the Salesforce Web Services API?
@ddkpe,
I am having the same issue with them being different. Did you ever figure this one out?