• Nashorn
  • NEWBIE
  • 5 Points
  • Member since 2005

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 3
    Replies
I am writing an application that calls the DataLoader as an external Java process. For example:

String str="java -jar -Dsalesforce.config.dir=C:/dataloader/ C:\bin\sforcedataloader.jar";
Process p = Runtime.getRuntime().exec(str);
p.waitFor();

I have two related problems regarding error handling.

1) Sometimes when the DataLoader has a problem connecting to the salesforce.com service the exec() method doesn't return, and my program runs indefinitely (wheareas if you run the DataLoader from the command line and it has a problem connecting then you simply get another input prompt after the error message has been displayed in the log4j output and the DataLoader then stops running).

The Process class doesn't seem to give much feedback as to what is going on with a running process. Does anyone know how I can stop my program from hanging when the DataLoader has such a connection error?

2) At least I can parse through the log4j output that the DataLoader produces. Maybe the solution to the previous question is simply something like:

BufferedReader stdOutput = new BufferedReader(new InputStreamReader(p.getInputStream()));
            
String str = "";

System.out.println("DataLoader standard output:\n");
while ((str = stdOutput.readLine()) != null) {
    System.out.println(str);
    //parse string and decide if something needs to be done
    //if determine for instance that the connection failed, call p.destroy() and then let my java program continue executing
}

My question in this case is, what exactly do I need to search for in this string for in order to gracefully handle the errors that are returned by the DataLoader? Some DataLoader errors will be ok, such as when a record is updated with a value that is the wrong data type. However, I want to single out all fatal errors, such as a connection problem.

Any hints as to how I can get a list of what exceptions/errors that I need to watch for would be appreciated!

I need to know how to determine if the salesforce services are available, perferably without using the salesforce API itself (i.e. without SforceServiceLocator, LoginResult, etc).

I am reasoning that since the salesforce API uses Web Services, which are based on HTTP, then it is reasonable to assume that if
https://www.salesforce.com/login.jsp
does not return anything then that means that the salesforce Web Services are also not available.

I am also basing this theory on the fact that one time I was trying to use the DataLoader and kept getting some kind of connection error (it said "PartnerClient connection error" or something like that). When I went to
https://www.salesforce.com/login.jsp
it was also unavailable. About 10 minutes later the DataLoader was able to connect ok, and I was also able to retrieve a page from
https://www.salesforce.com/login.jsp,
which makes me think that it is a reasonable assumption.

So basically, I am hoping that I can get away with doing something simple like this:

//test if sfdc web services are available
try {
    URL url = new URL("https://www.salesforce.com/login.jsp");
    URLConnection conn = url.openConnection();
    /**
    * Check if the value of the first header value is null (if
    * everything is ok then it should be something like "HTTP/1.1 200
    * OK")
    */
    String headerName = conn.getHeaderFieldKey(0);
    String headerValue = conn.getHeaderField(0);
    if (headerValue != null) {
        //success
    } else {
        //failure

    }
    conn = null;
} catch (Exception e) {
    //exception
}



The only question I have is if this will always correctly tell me if the salesforce services are available.

Thanks for any help!

Message Edited by Nashorn on 04-04-2006 03:10 AM

I am programming with AJAX and am trying to set some fields to null on an object.

I tried this, but it didn't work:

var opportunity = queryResult.records[0]; //an opportunity pulled from the database
var aFieldsToNull = new Array(1);
aFieldsToNull[0]= "field_name__c";
opportunity.set("fieldsToNull", aFieldsToNull);

I tried this, but it also didn't work:

var aFieldsToNull = new Array(1); //an opportunity pulled from the database
aFieldsToNull[0]= "field_name__c";
var propNull = new DynaProperty("fieldsToNull",aFieldsToNull);
opportunity.addProperty(propNull);

Does anyone know how to set a field to null? The only info I have found on this message board is this hack: http://forums.sforce.com/sforce/board/message?board.id=general_development&message.id=4794

I am hoping that there is a better way to do this.

Thanks for any help!

Message Edited by Nashorn on 01-16-2006 01:05 AM

I am developing an S-Control using the AJAX API. I have a problem that pertains to sorting a SOQL result set. With normal SQL you can just use ORDER BY, but not with SOQL. As a consequence, I have to load every single data record with Javascript and then sort it. But all that I want is a subset of the data, e.g records 150 to 250 from the result set (but remember, I want records 150 to 250 from the complete _sorted_ result set). The problem occurs when I load all of the data at one time with Javascript in order to sort it. The browser starts to perform poorly and sometimes shuts down the script because too much memory is being used. Is there any way around this sorting problem?


More concretely, here is what I am doing:


//get all Contact ids (for an Account, for example)
var queryString="Select ContactId From Account where AccountId = 'xBLAHBLAH'";
var queryResult=sforceClient.Query(queryString);


//code left out for brevity:
     //get all results using queryResult = sforceClient.QueryMore(queryResult.queryLocator)
     //while doing this use queryResult[i].get("ContactID") to store all contact ids in an array named ContactIds


//so at this point we have thousands of contact ids stored in an array named ContactIds


// Now what I want to do is have the data sorted, and then get only part of it, such as records 150 to 250, from 1000 total records.
// If SOQL had ORDER BY, the records would already be sorted, and I would make the following call, using a subset of ContactIds from index 150 to 250
// ie ContactIds.slice(150,250)


ContactRecords = sforceClient.Retrieve("Salutation, LastName, FirstName, AccountId, Email", "Contact", ContactIds.slice(150,250));


// But since SOQL does not have ORDER BY, I have to load every single record, sort them, and then pick out the subset of indexes 150 to 250.
// Loading thousands of records in order to sort them uses too much memory.


 


I hope that the problem is clear, and thanks for any help.


If there is no solution, then I'll just have to forget about sorting the data.

Message Edited by Nashorn on 12-02-2005 02:01 AM

I need to know how to determine if the salesforce services are available, perferably without using the salesforce API itself (i.e. without SforceServiceLocator, LoginResult, etc).

I am reasoning that since the salesforce API uses Web Services, which are based on HTTP, then it is reasonable to assume that if
https://www.salesforce.com/login.jsp
does not return anything then that means that the salesforce Web Services are also not available.

I am also basing this theory on the fact that one time I was trying to use the DataLoader and kept getting some kind of connection error (it said "PartnerClient connection error" or something like that). When I went to
https://www.salesforce.com/login.jsp
it was also unavailable. About 10 minutes later the DataLoader was able to connect ok, and I was also able to retrieve a page from
https://www.salesforce.com/login.jsp,
which makes me think that it is a reasonable assumption.

So basically, I am hoping that I can get away with doing something simple like this:

//test if sfdc web services are available
try {
    URL url = new URL("https://www.salesforce.com/login.jsp");
    URLConnection conn = url.openConnection();
    /**
    * Check if the value of the first header value is null (if
    * everything is ok then it should be something like "HTTP/1.1 200
    * OK")
    */
    String headerName = conn.getHeaderFieldKey(0);
    String headerValue = conn.getHeaderField(0);
    if (headerValue != null) {
        //success
    } else {
        //failure

    }
    conn = null;
} catch (Exception e) {
    //exception
}



The only question I have is if this will always correctly tell me if the salesforce services are available.

Thanks for any help!

Message Edited by Nashorn on 04-04-2006 03:10 AM

I am programming with AJAX and am trying to set some fields to null on an object.

I tried this, but it didn't work:

var opportunity = queryResult.records[0]; //an opportunity pulled from the database
var aFieldsToNull = new Array(1);
aFieldsToNull[0]= "field_name__c";
opportunity.set("fieldsToNull", aFieldsToNull);

I tried this, but it also didn't work:

var aFieldsToNull = new Array(1); //an opportunity pulled from the database
aFieldsToNull[0]= "field_name__c";
var propNull = new DynaProperty("fieldsToNull",aFieldsToNull);
opportunity.addProperty(propNull);

Does anyone know how to set a field to null? The only info I have found on this message board is this hack: http://forums.sforce.com/sforce/board/message?board.id=general_development&message.id=4794

I am hoping that there is a better way to do this.

Thanks for any help!

Message Edited by Nashorn on 01-16-2006 01:05 AM