I have a Spring Bean config to login to Salesforce using the Enterprise API. It looks like follows:
@Bean(name="loginToSalesforceProductionEnterprise")
public EnterpriseConnection loginToProductionSalesforceEnterprise() {
try {
final ConnectorConfig config = new ConnectorConfig();
config.setUsername("[email protected]""username");
config.setPassword("l3nd!ngclubK9hnXZVFhnwFH4kwP9rgZ8ii""password");
config.setAuthEndpoint("https://login.salesforce.com/services/Soap/c/29.0");
enterpriseConnection = new EnterpriseConnection(config);
} catch (ConnectionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return enterpriseConnection;
}
Then I have a Junit Test to my login:
package com.sforce.authentication;
import static org.junit.Assert.*;
import javax.inject.Inject;
import javax.inject.Named;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;
import com.sforce.soap.enterprise.sobject.wsc.Account;
import com.sforce.soap.enterprise.wsc.EnterpriseConnection;
import com.sforce.soap.enterprise.wsc.SaveResult;
import com.sforce.ws.ConnectionException;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(loader=AnnotationConfigContextLoader.class, classes={SalesforceAuthenticationConfigImpl.class})
public class EnterpriseConnectionTest {
@Inject @Named("loginToSalesforceProductionEnterprise") EnterpriseConnection loginToSalesforceEnterpriseConnection;
@Test
public void test() throws ConnectionException {
Account newAccount = new Account();
newAccount.setName("Test");
SaveResult[] sr = loginToSalesforceEnterpriseConnection.create(new Account[]{newAccount});
System.out.println(sr[0].getSuccess());
assertNotNull(sr);
}
}
The test just never completes and seems to be stuck, but when I go look in Salesforce I can see the Account has been created. Looks like SaveResult[] never returns anything but it also doesn't fail. Any suggestions?