function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Code MonkeeCode Monkee 

Sample code for a filtered query needed.

Are there any java code samples available for performing a filtered query? 

Also, when can we expect to see java sample code available for download? (and why are those VB.NET and C# people the lucky ones?)

mobileTestmobileTest

What part do you want a sample for?  Building the filter object?  I'm no java developer but I think you should be able to implement this.  These were adapted from the C# samples.

 

   java.lang.object[] ret;
   java.lang.object[] filter = new java.lang.object[1]; //Final filter array

//MyID is a parameter from the calling app

   filter[0] = MakeSimpleFilter(new java.lang.object("ownerID"), MyID, new java.lang.string("equals"));

//Helper function to enhance code readability

  private sForceConn.mapEntry[] MakeSimpleFilter(java.lang.string Field, java.lang.object Value, java.lang.string Operator)
  {

//sForceConn is the binding or proxy client to sfconnector

   sForceConn.mapEntry[] Filter = new sForceConn.mapEntry[3];
   Filter[0] = new sForceConn.mapEntry();
   Filter[1] = new sForceConn.mapEntry();
   Filter[2] = new sForceConn.mapEntry();

   Filter[0].key = "field";
   Filter[0].value = Field;

   Filter[1].key = "value";
   Filter[1].value = Value;

   Filter[2].key = "operator";
   Filter[2].value = Operator;

   return Filter;
  }

This is the most basic of filters.  Although the documentation states that there is an implied equality operator, it will be easier to manage more complex filters if the operator is handled explicitly.

Here is a logical and filter:

   java.lang.object[] ret;
   java.lang.object[] filter = new java.lang.object[1]; //Final filter array
   java.lang.object[] andFilter = new java.lang.object[2]; //and'd filter

   //Create simple filter as first part of and'd filter
   andFilter[0] = MakeSimpleFilter(new java.lang.string("ownerID"), MyID, new java.lang.string("equals"));
   //Create simple filter as second part of and'd filter
   andFilter[1] = MakeSimpleFilter(new java.lang.string("title"), new java.lang.string("President"), new java.lang.string("starts with"));

   //Create complex final and'd filter
   filter[0] = MakeAndOrFilter(andFilter, new java.lang.string("and"));

//helper function for readability

  private sForceConn.mapEntry[] MakeAndOrFilter(java.lang.object Value, java.lang.string Operator)
  {
   sForceConn.mapEntry[] Filter = new sForceConn.mapEntry[2];
   Filter[0] = new sForceConn.mapEntry();
   Filter[1] = new sForceConn.mapEntry();

   Filter[0].key = new java.lang.string("value");
   Filter[0].value = Value;

   Filter[1].key = new java.lang.string("operator");
   Filter[1].value = Operator;

   return Filter;
  }

As you can see, the filter gets complex quickly.

 

Message Edited by mobileTest on 06-25-2003 01:57 PM

Code MonkeeCode Monkee
Thanks, the key clue here for me was that "operator" was the third child element of the filter.item element. And away we go....
SantoSanto

I would like to know if you could post the code that do the filtering in Java. I am trying to learn how to filter information using the sample code.  I just started and it might take a while for me do get it correct.

 

 

adamgadamg

Check out the new Java samples that were posted to this forum in a different thread - should provide all the information you need.