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
kevincarkevincar 

API 2.0 Headache

 

Hi all,

I'm trying to run a query for an account object that has a particular social sec. # (a custom field), but I keep on getting a message saying "Bad field name 'site' in select list of query call".   Is there something I'm missing? I verified I'm using API version 2.0 and verified the WSDL has "SSN_c" as the field name .  Here's my code:

    Object[] filter = new Object[1]; //Final filter array
    Calendar jc = Calendar.getInstance();
    jc.set(1950,10,6);
    filter[0] = makeSimpleFilter("SSN__c", sSqlRetData, "equals");

    org.w3c.dom.Element a_value = (org.w3c.dom.Element)   binding.query("filter", "account", 10,
               new java.lang.String[] {"SSN__c"}, filter, null, jc, true);

Thanks in advance for any help.

KC

 

Message Edited by kevincar on 12-11-2003 01:57 PM

DevAngelDevAngel

Hi kevincar,

The 2.0 version of the api has a different naming convention for custom fields.  If you do a describe call on you account object you should see the the field you created for social security number has a name like cf_00N30000000csXE.

You should modify your code to look like this (replacing cf_00N30000000csXE with you custom field name from the describe call):

    Object[] filter = new Object[1]; //Final filter array
    Calendar jc = Calendar.getInstance();
    jc.set(1950,10,6);
    filter[0] = makeSimpleFilter("cf_00N30000000csXE", sSqlRetData, "equals");

    org.w3c.dom.Element a_value = (org.w3c.dom.Element)   binding.query("filter", "account", 10,
               new java.lang.String[] {"cf_00N30000000csXE"}, filter, null, jc, true);

 

RichardRichard
this method takes a describe call as a DOM Element and a field label and converts the label to the custom field name...

public String convertCustomFieldName( Element description, String thisLabel) throws DOMException, TransformerException, ServiceException, RemoteException, MalformedURLException
{
String ourFieldName = "";
boolean found = false;

NodeList fieldList = null;
Node singleNodes = null;
Node detail = null;

String custom = "";

boolean isCustomField = false;

String fieldName = "";

String label = "";
MapEntry fieldData = null;

fieldList = XPathAPI.selectNodeList
for (int i=0; i < fieldList.getLength(); i++)
    {
       singleNodes = fieldList.item(i);

       detail = XPathAPI.selectSingleNode(singleNodes, "field/text()" );
       fieldName = detail.getNodeValue();

       detail = XPathAPI.selectSingleNode(singleNodes, "custom/text()" );
       custom = (detail != null) ? detail.getNodeValue() : false;
       isCustomField =       Boolean.valueOf(custom.trim()).booleanValue();

       if(isCustomField)
       {
          detail = XPathAPI.selectSingleNode(singleNodes, "label/text()" );
          label = (detail != null) ? detail.getNodeValue() : ;
          if( thisLabel.equals(label) )
          {
             ourFieldName = fieldName;
             found = true;
          }
       }
    }
    if(found == false)
    {
       ourFieldName = thisLabel;
    }
    return ourFieldName;
}



It is not the most ideal implementation as the XPaths are not pre-compiled and it is not using the DOM structure in the most intelligent way but it will do the trick!!

Also... it is best to cache describe calls rather than request them from the server everytime you need them... better for your application and better for Salesforce

Hope this helps
Richard

Message Edited by Richard on 12-12-2003 02:54 PM

Message Edited by Richard on 12-12-2003 02:55 PM