I'm trying to find a better way to show employee detail when the user clicks on the user name.

My question is: Do I need to add another SOQL query or I can use what I have?, so when the user clicks on the employee name, I want to show detail like Salary, Address, etc...

I need help in building SOQL query.

my APEX code:

 String myId = System.currentPagereference().getParameters().get('id'); 
 employeeSQL = [SELECT id,name,RecordType.Name FROM Employee__c WHERE Id = :myId];

  for(Employee__c e : employeeSQL ){

Data Data

Employee_Detail__c: {
    Name=John Smith, 
    Address__c=123 main st ca 90717,    
Employee_Detail__c: {
    Name=John Erich, 
    Address__c=123 main st ca 90717,    

enter image description here

  • 1
    A common approach to modelling people (including employees) is to add any necessary custom fields (and record types) to Contact so there is only a single object rather than a completely custom object or some fields in a one object and some fields in another object. One SObject for one domain object keeps code simple. – Keith C Feb 24 '16 at 22:08

You can add the data to an existing query as a sub-query, basically like so:

SELECT Name, (SELECT Name, Salary__c, Address__c FROM Employee_Details__r) FROM Employee__c ...

In Visualforce, you can iterate over those details using the apex:repeat, apex:dataTable, or apex:pageBlockTable elements as you desire. You'll need to add a bit of Visualforce logic to actually show/hide the elements, but that should be pretty trivial.

  • i'm getting this error Didn't understand relationship 'employee_Detail__r' in FROM part of query call – Nick Kahn Feb 24 '16 at 22:13
  • Check the relationship field on employee detail object. It may be a different name. – sfdcfox Feb 24 '16 at 22:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.