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
SidharthSidharth 

Apex -> Login Second User -> Get Session Id

Is there a way to login another user in the apex class, to get the session id of that user. I probably can do it using the soap Login call within apex, passing username and password for the second user, and get the session id. But wondering if there is a shortcut for the same.

Thanks.
Sid
SidharthSidharth
Use Case: In our custom customer portal, we are creating the REST api in sf, which will create the portal user using username and password from the regustration form on the portal site. REST api shoud return the session id the new portal user, to directly login him to the portal.
BalajiRanganathanBalajiRanganathan
You can try to do Http Call out for OAUTH token in the rest API.

​https://www.salesforce.com/us/developer/docs/api_rest/Content/intro_understanding_username_password_oauth_flow.htm
SidharthSidharth
Thansk for the reply, but i duobt it can done for portal users, but just for full sf users.
BalajiRanganathanBalajiRanganathan
it seems that is possible.
https://developer.salesforce.com/blogs/developer-relations/2013/02/oauth-for-portal-users.html
SidharthSidharth
Ya buts it assumes we are using sf site for the customer portal, but in our case we are building custom customer portal.