2

I am trying to query contacts from salesForce account but getting above error.

I generated enterprise.jar file from the WSDL downloaded from my account.

I have wsc-23-min.jar along with enterprise.jar files in libs folder.

Below method is used to query contacts

private void queryContacts() {
    Log.i(TAG, "Querying for the 5 newest Contacts...");

    ConnectorConfig config = new ConnectorConfig();
    config.setUsername("***@***.com");
    config.setPassword("***");

    try {

        connection = Connector.newConnection(config);
        // query for the 5 newest contacts      
        com.sforce.soap.enterprise.QueryResult queryResults = connection.query("SELECT Id, FirstName, LastName, Account.Name " +
                "FROM Contact WHERE AccountId != NULL ORDER BY CreatedDate DESC LIMIT 5");

        if (queryResults.getSize() > 0) {
            for (int i=0;i<queryResults.getRecords().length;i++) {
                // cast the SObject to a strongly-typed Contact
                Contact c = (Contact)queryResults.getRecords()[i];
                Log.i(TAG, " ------------- Id: " + c.getId() + " - Name: "+c.getFirstName()+" "+
                        c.getLastName()+" - Account: "+c.getAccount().getName());
            }
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
}

Any help or clue is appreciated. Thanks.

Edit:

I tried all the methods from this popular question but no luck.

I have other projects in my workspace which are having jar files (in 'libs' folder) and they all work properly. Don’t know whats wrong with salesforce related jar files.

Edit:

There is no problem with wsc-23.jar file. Classes placed in this jar, for ex. Connector and others loading and they are working fine.

Only problem is with generated enterprise.jar through WSDL file.

Followed this to generate enterprise.jar file

Not getting what's wrong with it.

Community
  • 1
  • 1
Braj
  • 2,164
  • 2
  • 26
  • 44

2 Answers2

2

You should place your jar in libs folder not in lib folder. After that goto Project properties and add the jar to java build path.

Sunny
  • 14,522
  • 15
  • 84
  • 129
  • Sorry. I edited my question. All jars are in libs folder only. NOT in lib. Even I follwed http://android.foxykeep.com/dev/how-to-fix-the-classdefnotfounderror-with-adt-17 post but no luck. – Braj Dec 18 '13 at 05:37
  • Are your jars appear in `Referenced Libraries`? – Sunny Dec 18 '13 at 05:41
  • Yes. They r appearing. – Braj Dec 18 '13 at 05:41
  • Possibly there may be something wrong with Order and export.Make sure your all custom libraries are below `YOURPROJECT/gen` and all are checked. – Sunny Dec 18 '13 at 05:45
  • All jars r below proj/gen folder. I was missing "checking" part but after doing that also no luck. – Braj Dec 18 '13 at 05:52
  • did you clean your project after that? – Sunny Dec 18 '13 at 06:19
0

Finally got the solution for my problem.

Here is a link for the answer.

Community
  • 1
  • 1
Braj
  • 2,164
  • 2
  • 26
  • 44