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
mallikammallikam 

SOQL query for look up objects?

I have controller method which is executed when the user selects a name from th lookup contact

on a visual force page. I want the SOQL query to get the email from the parent contact object based

on the name he selected from contact object...how should my query look like?

 

Here is how my controller class looks like but the query in test() is not doing the job. please help.

 

public class customObjectExtension {

 

private final customObject request{get; private set;}

public String employeeEmail = null;

 

 

public customObjectExtension(ApexPages.StandardController stdController) { this.request = (customObject)stdController.getRecord();

}

public String getEmployeeEmail() {

return employeeEmail;

}

public void setEmployeeEmail(String email) {

employeeEmail = email;

}

public PageReference Test(){

Contact info = [Select Email from Contact where

Contact.Name =: request.Employee_Name__r.Name] ;

employeeEmail = info.Employee_Name__r.Email;

return null;

}

}

Best Answer chosen by Admin (Salesforce Developers) 
mallikammallikam

thanks wes, yes, you are right. The problem is also with the query..(I resolved it for now..).

SELECT name, email FROM contact where id = :request.employee_name__c

 

I should post all of the related code from next time..I thought its too confusing but I think it is actually confusing if you

post half of the code..:)

All Answers

wesnoltewesnolte

Hey

 

Can you post the code from you page as well please? A few things, your access modifiers in the controller are a bit strange, perhaps try this

 

public class customObjectExtension {

 

private customObject request; //if it's not used in your page no need for getters & setters

private String employeeEmail = null; // you have getters and setters so no need to define this as public

 

 

public customObjectExtension(ApexPages.StandardController stdController) { this.request = (customObject)stdController.getRecord();

}

public String getEmployeeEmail() {

return employeeEmail;

}

public void setEmployeeEmail(String email) {

employeeEmail = email;

}

public PageReference Test(){

Contact info = [Select Email from Contact where

Contact.Name =: request.Employee_Name__r.Name] ;

employeeEmail = info.Employee_Name__r.Email;

return null;

}

}

 

Cheers,

Wes 

mallikammallikam

thanks wes, yes, you are right. The problem is also with the query..(I resolved it for now..).

SELECT name, email FROM contact where id = :request.employee_name__c

 

I should post all of the related code from next time..I thought its too confusing but I think it is actually confusing if you

post half of the code..:)

This was selected as the best answer
k2sfdevk2sfdev

Hi mallikam,

 

Do you use actionSupport to handle the rerender?

If so, which enent is used?

 

Thank you. 

mallikammallikam
I want to actually use onselect but since its not working for some reason with action support for the inputField with a lookup, I am using onclick..and its working fine