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
Mahboob AljiwalaMahboob Aljiwala 

How get any employee detail after login of particular employee without any click event ? (By Visualforce)

NagendraNagendra (Salesforce Developers) 
Hi Mahboob,

May I request you please be more specific on your requirement what you need to display on the visual force page?

Are you trying to display the logged in user details on the visual force page?

Or, the employee is a custom object in your database using which you want to display the employee details on the visual force page?

Please confirm so that we can understand better and can help you accordingly.

Thanks,
Nagendra
Mahboob AljiwalaMahboob Aljiwala
Hi Nagendra,

Thanks for reply..
 
The employee is a custom object in my database using which i want to display the employee details on the visual force page.
I want the details from employee object of that particular employee/user which has logged in.
NagendraNagendra (Salesforce Developers) 
Hi Mahboob,

Please find the code below which is working fine for me.

Visual Force Page:
<apex:page Controller="Employee" showheader="false">
  <apex:form >
   <script type='text/javascript'>
   function runOnEnter(ev) {
        if (window.event && window.event.keyCode == 13 || ev.which == 13) {
            searchEmpRecs();
            return false;
        } else {
            return true;
        }
}
</script>
 <apex:inputText value="{!searchString}" onkeypress="return runOnEnter(event);"/>
  <apex:commandButton value="Submit" action="{!searchEmp}" reRender="pgblcktbl"/>
    <apex:pageBlock title="Employee Details">
     <apex:pageBlockTable value="{!empList}" var="emp" id="pgblcktbl">
        <apex:column value="{!emp.First_Name__c}"/>
           <apex:column value="{!emp.Last_Name__c}"/>
             <apex:column value="{!emp.EmpID__c}"/>
               <apex:column value="{!emp.Email__c  }"/>
                 <apex:column value="{!emp.contact__c}"/>
                <apex:column value="{!emp.cityy__c}"/>
               <apex:column value="{!emp.Address__c}"/>
             <apex:column value="{!emp.Department__c}"/>
        </apex:pageBlockTable>
        </apex:pageBlock>
      <apex:actionFunction name="searchEmpRecs" action="{!searchEmp}" reRender="pgblcktbl"/>
  </apex:form>
</apex:page>
Apex Controller:
public class Employee {

    public Employee() {
        empList = new List<Employees__c>();
        empList = [select id,First_Name__c,Last_Name__c,EmpID__c,Email__c,Department__c,contact__c,cityy__c,Address__c from Employees__c];
    }
   
    Public List<Employees__c> empList{get;set;}
    Public string searchString{get;set;}


   Public void searchEmp(){
        searchString += '%';
        empList = new List<Employees__c>();
        empList = [select First_Name__c,Last_Name__c,EmpID__c,Email__c,contact__c,cityy__c,Department__c,Address__c from Employees__c where First_Name__c like : searchString limit 10];
       
    }   
 }
Hope this helps.

Kindly mark this as solved if the reply was helpful.

Thanks,
Nagendra

 
Mahboob AljiwalaMahboob Aljiwala
Hi Nagendra,

Thanks for reply

As per my requirement this code is not working. My requirement is that if my any Employee do login at that time it should show details of that particular Employee which is logged in and details should come from Employee custom object. It should not show any other Employees details.