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
ssuede7ssuede7 

querying a contact object

     I want to access all of the cases from any case object associated with a particular contact.  however I CAN NOT figure out how to get the contact id out of the contact object. 

    also I tried to set the ownerid as a variable in jsp however it wouldn't convert to any primitive variable type.  I know this has something to do with the fact that the ownerid is a "tns" type as defined in the wsdl doc. 

     any help or insight on querying and referencing data in the contact or case objects would be extrememly helpful.  I'm working in JSP

Thank, Josh

DevAngelDevAngel

Hi ssuede7,

The id for any object is the "Id" field.  If you are starting with a case, you can fetch the contact using the ContactId field from the case - Select Id, FirstName, LastName from Contact Where Id = '" + contactId + "'"

If java, an Id is an object, so from your case object to get the value to stick in the query above, you might do something like  string contactId = case.getContactId().getValue();

To set an ownerId you would create a new ID instance ID ownerid = new ID();  and then set the value ownerid.setValue(userid) assuming the userid has a string.  if the userid is a userid then ID ownerid = userid;.

Does this help, or am I missing the nuance of the question?

ssuede7ssuede7

This is helpful yes, although we are coming at it from the opposite direction.  We are starting with a contact or contact id and attempting to query the cases for any cases that correspond to that contact.  We can't seem to get any results back from our query though.  Here is the code we are working with:

//obtain a contact

QueryResult qr = sforceLogin.getBindingStub().query("select firstname, lastname, title, email, ownerid, id from contact where firstname = '"+user+"' and lastname = '"+pass+"'");
Contact tContact = null;
if (qr.isDone()) {
tContact = (Contact)qr.getRecords(0);
}

ID cid = tContact.getId();

QueryResult qr2 = sforceLogin.getBindingStub().query("select id, casenumber from case where id = '"+cid+"'");

Any suggestions?

benjasikbenjasik
Don't you want:

"select id, casenumber from case where contactid = '"+cid+"'"); ?
ssuede7ssuede7
Yes, we figured that out too. Thanks for responding though.