I am building a Java application to interact with the different api's Salesforce provides such as Tooling Api, Metadata Api, Partner Api. I have several questions:

Is it possible to make the application log into any Salesforce Org and use the Tooling Api / Metadata Api for that org ? I know that Partner Api should be ok with that.

Thanks !


I was able to use the Tooling Api with the following approach:

ConnectorConfig toolingConfig = new ConnectorConfig ();
ToolingConnection soapConnection = new ToolingConnection(toolingConfig);

ConnectorConfig object is provided by the WSC.

ToolingConnection object is provided by the Tooling WSDL.

Is it the right way to use my org's Tooling API WSDL to connect (using username and password) to other Salesforce organizations as well?

2 Answers 2


Short answer is Yes.

There is a caveat - you do not login to SFDC using Tooling Api or Metadata APIs directly.
You have to use Partner API to login and obtain "API endpoint" + "Session Id", and then use this information in subsequent Tooling Api or Metadata API calls.

After login with Partner API you will get session Id and API endpoint.
Session Id you use as is, but endpoint need to be modified.

With Partner API it looks something like this:


In your Tooling API requests you will need to replace "/u/" with "/T/" to get something like:


Process with Metadata API Session Id and endpoint looks the same, except that in API endpoint you need to replace "/u/" with "/m/".
You can find exact values to use for replacement at the bottom of appropriate API WSDL file, in <service> node.

Since you are using java, I would also recommend checking out Force.com Web Service Connector (WSC). It will simplify many things for you.

  • Thanks @gaiser, one more question. I have started the app using WSDL so it provides me Java objects like Profile, Layout etc. With your approach I will not have these ?
    – sfdcdev
    Commented Jan 23, 2017 at 11:58
  • Hello @RonDaniel, what "approach" are you referring to? Nothing described in my answer prevents you from accessing the data (metadata). You will certainly be able to access Profile, Layout and any other data/metadata exposed via specific API.
    – gaiser
    Commented Jan 23, 2017 at 12:24
  • REST approach instead of SOAP
    – sfdcdev
    Commented Jan 23, 2017 at 12:42
  • Not sure why you call REST instead of SOAP "my approach" as I never suggested REST. In any case, with REST you will have access to pretty much same objects/data just in a different format (JSON instead of XML) and will not be able to use strongly typed Java classes generated from WSDL.
    – gaiser
    Commented Jan 23, 2017 at 17:15
  • I was able to use the Tooling Api with this URL: server-api.salesforce.com/services/Soap/T/XX.0/orgId But only when I created a ToolingConnection object provided by the Tooling Api WSDL. Is it ok to use arbitrary WSDL to connect (using username and password) to other Salesforce orgs as well? Is it the right way ?
    – sfdcdev
    Commented Jan 23, 2017 at 22:54

If your java application implements an oauth flow then it is definitely possible .

I would recommend you to explore oauth flow .For oauth you will create a connected app in your developer org .

Every time the user uses your java application they will go through the oauth flow and you will have user context .

Here is a simple servlet link to guide you

  • Thanks for answering, if I understand it correctly, with this approach I must configure some settings in the org. I would like the application to be able to connect to any org.
    – sfdcdev
    Commented Jan 23, 2017 at 22:39
  • Have you looked workbench ?workbench.developerforce.com/login.php .To connect to workbench do you configure anything in your salesforce org ?You use oauth here .Only in one developer org you will maintain a connected application and then in your java app you will securely store the clientId and cliensecret for you to complete oauth dance .It does not mean in all orgs you will configure something .Updated answer with a servlet link Commented Jan 23, 2017 at 22:45
  • There is something I guess I don't understand. My application requests the user to enter a username and password. You say that I will be able to log into my org and also you will be able to use it for your org as well. without any configuration. right ?
    – sfdcdev
    Commented Jan 23, 2017 at 22:49
  • Yes .So you will provide a button that will say Login to salesforce.com .The user will go to salesforce login screen ,Enter Username and password and comeback to SFDC with refresh and access token .Asking user to enter username and password and then storing is security threat ,if you do not store them encyrpted .Instead an oauth flow saves you from all this Commented Jan 23, 2017 at 22:54
  • Could you please elaborate? I didn't understand the idea. Also, let's say I am done and I logged in , will I be able to use SOAP ? or Rest Only ?
    – sfdcdev
    Commented Jan 23, 2017 at 22:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .