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
DMDM 

trouble compiling using a custom object

Hi,

First I would like to thank those who provided guidance to my previous questions. I have another newbie question for you.

I have been able to successfully compile and run the quickstart.java and samples.java code based on the information previously provided.

I am trying to create a java class which will allow me to query and update a custom object I created in the developer edition. The object is called cognos__c in the enterprise wsdl file I generated.

The following is the import statements and query function I have based on the samples. I want to write a query which will allow me to retrieve the object's id:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import java.text.DateFormat;
import java.util.Calendar;
import java.util.Date;

import javax.xml.rpc.ServiceException;

import com.sforce.soap.enterprise.DescribeGlobalResult;
import com.sforce.soap.enterprise.DescribeSObjectResult;
import com.sforce.soap.enterprise.Field;
import com.sforce.soap.enterprise.FieldType;
import com.sforce.soap.enterprise.GetUserInfoResult;
import com.sforce.soap.enterprise.ID;
import com.sforce.soap.enterprise.LoginResult;
import com.sforce.soap.enterprise.PicklistEntry;
import com.sforce.soap.enterprise.QueryResult;
import com.sforce.soap.enterprise.ResetPasswordResult;
import com.sforce.soap.enterprise.SaveResult;
import com.sforce.soap.enterprise.SetPasswordResult;
import com.sforce.soap.enterprise.SforceServiceLocator;
import com.sforce.soap.enterprise.SoapBindingStub;
import com.sforce.soap.enterprise._QueryOptions;
import com.sforce.soap.enterprise._SessionHeader;
import com.sforce.soap.enterprise.fault.ExceptionCode;
import com.sforce.soap.enterprise.fault.LoginFault;
import com.sforce.soap.enterprise.sobject.Account;
import com.sforce.soap.enterprise.sobject.Contact;
import com.sforce.soap.enterprise.sobject.SObject;
import com.sforce.soap.enterprise.sobject.Task;
import com.sforce.soap.enterprise.sobject.User;
import com.sforce.soap.enterprise.fault.*;

 

private void query(){

  QueryResult qr = null;
  _QueryOptions qo = new _QueryOptions();
  qo.setBatchSize(new Integer(3));
  binding.setHeader("SoapService", "QueryOptions", qo);
  
  try
  {
   qr = binding.query("select id from cognos__c");
   
    for (int i=0;i<qr.getRecords().length;i++)  {
     cognos__c con = (cognos__c) qr.getRecords()[i];
     String id = con.getId();
     System.out.println("id " +id);
    }
    
    
   


        System.out.println("\nQuery succesfully executed.");
   getUserInput("\nHit return to continue...");
                      } catch (UnexpectedErrorFault uef) {
                              System.out.println(uef.getExceptionMessage());
                      } catch (Exception ex)
  {
   System.out.println("\nFailed to execute query succesfully, error message was: \n"
        + ex.getMessage());
   getUserInput("\nHit return to continue...");
  }


 }

When I try to compile my java source code from a command prompt using the command line:

javac Custom.java

where Custom is the name of the class containing the above code,  I get the following error

Custom.java:474: cannot resolve symbol
symbol  : class cognos__c
location: class Custom
                                        cognos__c con = (cognos__c) qr.getRecords()[i];
                                        ^
Custom.java:474: cannot resolve symbol
symbol  : class cognos__c
location: class Custom
                                        cognos__c con = (cognos__c) qr.getRecords()[i];
                                                         ^
2 errors

I know I need to let the Java compiler know about my custom object but I am unclear on how I do this. I am assuming I would use an import statement in my Custom.java class. It seems like I need to generate Java code for the custom object cognos__c that I created in the developer edition but how would I do this? Or is there a parameter I should use when invoking Javac to let it know about the wsdl file?

Thanks for your help

DM

Message Edited by DM on 02-11-2004 11:37 AM

adamgadamg
Assuming you have regenerated your WSDL and proxies, you will also need to:

import com.sforce.soap.enterprise.sobject.*;

You should have an object cognos__c in that package; if you don't you'll need to do the WSDL/proxy generation (there are instructions on how to do this in the doc using WSDL2Java; many IDEs will do this automatically.)