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
hegde_hegdekhegde_hegdek 

using {!$Api.Session_ID} for authentication in google app engine for java

Hello,

I want to write a google app engine java force.com application,which will be embbeded within force.com,can i use

{!$Api.Session_ID} for authentication if so how.

regards

kaushik

Abhinav GuptaAbhinav Gupta

You will need server url together with SessionId to make things work best. though you can hard code server url, to start with also.

 

The merge field for Partner v20 URL is {!API_Partner_Server_URL_200} and for enterprise you can use {!API_Enterprise_Server_URL_200}

 

Using both SessionID + Server URL, one can authenticate and make SFDC WS API calls.

I don't know which client api you are using to generate stubs. But for Salesforce WSC API and partner WSDL following will be the code.

 

 

// Create new WSC Partner Connection
ConnectorConfig config = new ConnectorConfig();
config.setManualLogin(true);
// NOTE: replace server url 
config.setServiceEndpoint(SERVERURL);
// NOTE: replace sessionId
config.setSessionId(SESSIONID);
PartnerConnection partnerConn = Connector.newConnection(config);

// Create a new Contact
SObject contact = new SObject();
contact.setType("Contact");
contact.setField("FirstName", "Abhinav");
contact.setField("LastName", "Gupta");
SaveResult[] create = partnerConn.create(new SObject[] { contact });
for (SaveResult saveResult : create) {
    if (!saveResult.isSuccess()) {
        throw new RuntimeException(
                "Failed to save contact via Partner WSDL");
    }
}
System.out.println("Partner-WSDL : Save successfully done using WSC");