3

I have a method

import com.sforce.soap.enterprise.*;
import com.sforce.soap.enterprise.sobject.*;
....
    public static EnterpriseConnection connectToSalesforce()
    throws ConnectionException
    {
        EnterpriseConnection connection = null;

        String username      = "myname";
        String password      = "mysecret";
        String securityToken = "bigstring";
        String authEndPoint = "https://test.salesforce.com/services/Soap/c/24.0/";
        ConnectorConfig connConfig = new ConnectorConfig();
        connConfig.setUsername(username);
        connConfig.setPassword(password + securityToken);
        connConfig.setAuthEndpoint(authEndPoint);
        connection = new EnterpriseConnection(connConfig);

        return connection;
    }

that works great. Now I need to experiment with Metadata API so I copied the above with a few tweaks

import com.sforce.soap.enterprise.*;
import com.sforce.soap.enterprise.sobject.*;
import com.sforce.soap.metadata.*;
....
    public static MetadataConnection connectToSalesforceMetadata()
    throws ConnectionException
    {
        MetadataConnection connection = null;

        String username      = "myname";
        String password      = "mysecret";
        String securityToken = "bigstring";
        String authEndPoint = "https://test.salesforce.com/services/Soap/c/24.0/";
        ConnectorConfig connConfig = new ConnectorConfig();
        connConfig.setUsername(username);
        connConfig.setPassword(password + securityToken);
        connConfig.setAuthEndpoint(authEndPoint);
        connection = new MetadataConnection(connConfig);

        return connection;
    }

But connectToSalesforceMetadata() fails with a MalformedURLException. What's up with that?

Follow-on question: the Metadata API makes reference to a createMetadata() method that returns a SaveResult[] . But I don't have visibility to that method from neither an instance of EnterpriseConnection nor MetadataConnection . Am I missing an import ?

TIA,

Still-learning Steve

2

This did the trick. I use my already-working method to create an EnterpriseConnection then use that to create the MetadataConnection. Works like a charm.

    public static MetadataConnection connectToSalesforceMetadata()
    throws ConnectionException
    {
        MetadataConnection mconnection = null;

        EnterpriseConnection econnection = connectToSalesforce();
        LoginResult lr = econnection.login( econnection.getConfig().getUsername(), econnection.getConfig().getPassword());

        ConnectorConfig connConfig = new ConnectorConfig();
        connConfig.setSessionId( lr.getSessionId());
        connConfig.setServiceEndpoint( lr.getMetadataServerUrl());
        mconnection = new MetadataConnection( connConfig);

        return mconnection;
    }

Thanks to all to replied!

CASE CLOSED

Still-learning Steve

  • You can accept your answer now - you don't get any reputation points, but it's helpful for others! – metadaddy May 6 '14 at 16:49
1

On follow up question: "CreateMetadata" resource is available from API v30 onwards. As v30 is not GA yet, you need to connect to a prerelease spring14 org to avail this resource.

  • Ah, a versioning issue. Good catch! I'll stick with AsyncResult[] xxx = metadataConnection.create() then. – user1201168 Apr 1 '14 at 6:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.