You need to sign in to do that
Don't have an account?
Query Contacts from Acounts from a child custom object
Hello All,
I am writing a java client to lookup contacts from a custom object Acct__c. Acct__c has a lookup field Contact__c and another field Customer__c (Master detail with Account object. We renamed Account to Customer). I get Acct__c.ID as input to my client. I retrieve Contact__c and see if a Contact is associated with the that Acct__c, if not I get the Customer__c from Acct__c and try to look up the parent object i.e Customer (Account). Here is the code I have,,
SObject[] acct__cObjects = sfBinding.retrieve("Acct_Contact__c,Customer__c","Acct__c",sfId);
//Verify if the Account has any contact associated
for(int i=0;i<acct__cObjects.length;i++)
{
Acct__c acctObject = (Acct__c) acct__cObjects[i];
if(acctObject.getAcct_Contact__c() == null)
{
//Account has not contact get contacts from customer
String acctCustomer = acctObject.getCustomer__c();
//Query Customer
String contactQuery = "Select (Select Id, LastName, FirstName, MailingStreet,MailingPostalCode, Phone,FaxMailingState From Contacts) From Account a where a.id = '" + acctCustomer + "'";
QueryResult contactQr = sfBinding.query(contactQuery);
System.out.println(contactQr.getSize());
if(contactQr.getSize() > 0)
{
boolean done = false;
SObject[] results = contactQr.getRecords();
for(int r=0;r<results.length;r++)
{
Account customerContacts = (Account) results[r];
}
}
The point where I get stuck at is where I have to get the contacts thats the result of the query. When I try to do it like this
customerContacts.getContacts() //here getContacts is a QueryResult.
I believe I have to do a querymore() call there, but I am unsure how to do it though.Also, the statement (highlighted in red in the code) always gives a result of 1 irrespective of the fact that there is a contact in the Customer (Account) or not.
I'd appreciate if anyone helps me in this regard by directing me the right way. Thanks much.
Guys I got the problem solved, the issue. Thanks much.