+ Start a Discussion
pninthpninth 

java toolkit example not returning anything

i've downloaded the java toolkit and set everything up as instructed. when the sample program runs, i get an error after the login:

SEARCH RESULTS
java.lang.NullPointerException
        at test.api.SForce.search(SForce.java:264)
        at test.api.SForce.main(SForce.java:399)

i put a statement in the SForce class

           for (Iterator j = element.getChildElements(); j.hasNext() {
                     SOAPElement next = (SOAPElement) j.next();
                     result = SForceUtil.getObject(next, this.typeName);
                    System.out.println("result is"+result);
                 }

which prints out "result is null" when the sample is run

my understanding is that the sample searches for accounts with the word "test" in some field. i've put the word "test" in the website field of 3 accounts.

so i'm wondering what the problem is. has anyone got the toolkit to run properly? what needs to be put in the account fields?

Message Edited by pninth on 07-01-2003 10:29 AM

bobyrnebobyrne
This is probably related to the change to the XML return that coincided with the release of API 2.0.

Read the thread 'API 1.9 still available'. There is a modified version of the toolkit that correctly parses the new XML.

Brian.
DevAngelDevAngel

Hi Brian and Paul,

Actually, the problem lies in the field you are expecting to get hits from.  The search call is an optimized search that is limited to certain highly indexed fields.  As it happens, web site is not one of them.  Check the API documentation for specifics (detailed in the search call).

To verify if your search is working correctly or not, log into the application and do a "sidebar search".  In the application on the left of the window is a search box.  What ever is found using that should be found also using the API search call.

Cheers

pninthpninth

in the api documentation

"Indexed name fields are:. Account: Name, Site"

if this "Site" is not "Account Site" nor "Web Site", what is it?

do the fields listed in the API correspond to any fields in our SF account?

what am i missing?

i also tried creating an account called "test" it didn't find that either. is "Account Name" in SF Name in the API?

when i try the sidebar search, it is finding accounts with "test" in the "Account Site" field

but the api is not. is the api "turned on" for out sf account?

Message Edited by pninth on 07-02-2003 05:20 AM

Message Edited by pninth on 07-02-2003 05:25 AM

Message Edited by pninth on 07-02-2003 05:30 AM

DevAngelDevAngel

Hi pninth,

The Site field referenced in the documentation corresponds to the Account Site in the UI and is not the web site. 

Your search should locate the account that you created and named test.  Please post the message that your are sending for analysis.

larry.lefeverlarry.lefever

This isn't exactly working "out of the box" -- not that that was promised.  However, I'd gotten the impression that that's the way it was supposed to run.

The response is empty (and therefore uninformative).

The example throws a RuntimeException to the console, instead of catching it (testing for null, really) and indicating what that probably means.

Is the example supposed to run "out of the box"?  If not, what all do I need to do to make it run?

I, at first, tried to use Web Services Pack 1.2, but had a problem, saw a newsgroup-item about that, and changed to 1.1.

I'm running under Win98, using j2sdk1.4.2

 

>run.bat

You are connecting to http://na1.salesforce.com/servlet/servlet.SoapApi

Username: larry.lefever@verizon.net
Password: password
SearchValue: test
Scope all

com.sun.xml.messaging.saaj.soap.dom4j.BodyImpl@12f0999 [Element: uri: http://schemas.xmlsoap.org/soap/envelope/ attributes: []/>]
SEARCH RESULTS
java.lang.NullPointerException
        at test.api.SForce.search(SForce.java:262)
        at test.api.SForce.main(SForce.java:400)

>run.bat

You are connecting to http://na1.salesforce.com/servlet/servlet.SoapApi

Username: larry.lefever@verizon.net
Password: password
SearchValue: DecisionSmith
Scope name

com.sun.xml.messaging.saaj.soap.dom4j.BodyImpl@1d7ad1c [Element: uri: http://schemas.xmlsoap.org/soap/envelope/ attributes: []/>]
SEARCH RESULTS
java.lang.NullPointerException
        at test.api.SForce.search(SForce.java:262)
        at test.api.SForce.main(SForce.java:400)

>

 

    public static void main(String[] args){
        SForce client = null;
        String username = null;
        String password = null;
        String searchValue = null;
        String scope = null;
 
        System.out.println("\nYou are connecting to " + API_URL );
        System.out.println();
        System.out.print("Username: ");
        username = getString();
        System.out.print("Password: ");
        password = getString();
        System.out.print("SearchValue: ");
        searchValue = getString();
        System.out.print("Scope ");
        scope = getString();
       
        System.out.println();
        try {
            client = new SForce(API_VERSION, API_URL);
            if (client.login(username, password)) {
                if (client.describe(ACCOUNT)) {
                    //if (client.search("all", ACCOUNT, searchValue, 5)) {
                    if (client.search("all", scope, searchValue, 5)) {
                        // create select list and filters for query request
                        List select = new ArrayList();
                        select.add("id");
                        select.add("name");
                        select.add("industry");
                        List filter = new ArrayList();
                        String[] criteria = new String[2];
                        criteria[0] = TYPE_LOCAL;
                        criteria[1] = "Investor";
                        filter.add(criteria);
                        client.query(ACCOUNT, select, filter, 5);
                    }
                }
            }

 

 

see: https://na1.salesforce.com/00130000000aiGh for my customer-login-view

username: larry.lefever@verizon.net

password: password

pninthpninth

here is the soap message being sent out and the return. it looks like id's are being returned, but then why is the result null (the null pointer exception)?

(using the SForceUtil class to print out the messages)


the search message


http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="salesforce" xmlns:types="salesf
orce/encodedTypes" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" so
ap-env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
 
 
   1.9
   NoelXudGO6Yc5Wnw8DTHniB3g8kPTpmMxkQIjIFeBKyGeFHCPzPV.3zKiyZ3pKl2J_QovD4YWFxo7u1aRpr7J.btzKg
gVlhL
 
 
 
 
   all
   account
   test
   5
 
 

the search response


http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/enc
oding/" xmlns:tns="salesforce" xmlns:types="salesforce/encodedTypes" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instanc
e" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 
 
 
  
    00130000000ZnzK
    00130000000ImFO
    00130000000ImFP
  
 
 


result is null
SEARCH RESULTS
java.lang.NullPointerException
        at test.api.SForce.search(SForce.java:317)
        at test.api.SForce.main(SForce.java:451)

Message Edited by pninth on 07-07-2003 11:30 AM

pninthpninth

i've traced it down to getObject in SforceUtil

 String type = element.getAttributeValue(typeName);

type is coming back null, so obj is never assigned a value

 

SantoSanto

I am new to SForce and I have the same problem with the Java code as other developers in the community.

What was the solution to this problem?

==========================

java.lang.NullPointerException

 at SForce.search(SForce.java:259)

 at SForce.main(SForce.java:386)

SEARCH RESULTS

Message Edited by Santo on 07-17-2003 12:41 PM

pninthpninth

there are 2 problems with the "toolkit". although i was able to locate them, didn't know how to solve them till i read bobyrne 's post. so here is what i did:

1. in SForce.java

    public SForce(String version, String url) throws MalformedURLException, SOAPException {
        SOAPMessage msg = createMessage();
        SOAPEnvelope env = msg.getSOAPPart().getEnvelope();
        this.typeName = env.createName(TYPE_LOCAL, "xsi", "http://www.w3.org/2001/XMLSchema-instance");

        this.urlObj = new URL(url);
        this.version = version;
    }

you need to add parameters to env.creatName() as shown above

2. the data types

in SForceConstants.java, you need to define another set of types:

  // type constants
  String RETURN = "return";
  String VALUE_MAP = "valueMap";
  String DEBUG = "debug";
  String ARRAY = "array";
  String ARRAY_2 = "tns:array";
  String MAP = "map";
  String MAP_2 = "tns:map";
  String MAP_ENTRY = "mapEntry";
  String VALUE = "value";
  String STRING = "string";
  String STRING_2 = "xsd:string";
  String INTEGER = "int";
  String INTEGER_2 = "xsd:int";
  String BOOLEAN = "boolean";
  String BOOLEAN_2 = "xsd:boolean";

ie, the _2 ones,

then in SForceUtil.java, edit the getObject() method as below

 // Utility function to traverse SOAP response
 public static Object getObject(SOAPElement element, Name typeName) {
        Object obj = null;
        String type = element.getAttributeValue(typeName);
        if (type != null) {
            if (type.equals(INTEGER) || type.equals(INTEGER_2)) {
                obj = new Integer(element.getValue());
            } else if (type.equals(BOOLEAN) || type.equals(BOOLEAN_2)) {
                obj =  java.lang.Boolean.valueOf(element.getValue().equals("true"));
            } else if (type.equals(MAP)|| type.equals(MAP_2)) {
                obj = getMap(element, typeName); 
            } else if (type.equals(ARRAY) || type.equals(ARRAY_2)) {
                obj = getList(element, typeName);
            } else {
                obj = element.getValue(); 
            }
        }
       
        return obj;
    }
}

SantoSanto

After making the changes to the program, it run without problem.

Thanks.

AWilkinsonAWilkinson
Mine still is not working, could you post the entire modified codes? thanks!
SantoSanto

Check my reply for this problem in the message list. However, I have a similar problem with the query section of the code. I noted that it is a combination of thing that need to be setup in order for the code to run.

My email is srosario@patientcare.com. I can send you my code if you want.

AWilkinsonAWilkinson
Thank you Santo, really helpful!
plpl

Hi,

 

Anybody can tell me where you download the java toolkit example.

 

Thanks a lot

 

peilei