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
Deepak agarwal 9Deepak agarwal 9 

onclick get related data

Hi All,
 
Below is Vf code.The issue is when i click on any name i should get its related data.
Example :IF  name is Deepak if i click on deepak i should get its related data like its related account name and all.


Thanks,
Deepak
<apex:page controller="conrec1" sidebar="false" showHeader="false">
<apex:pageBlock title="Search for the contact">
<apex:form >
<apex:inputText value="{!data}"/>
<apex:commandButton value="Search"/>
<apex:pageBlockTable title="Contact" var="f" value="{!data1}" columns="3">
<apex:column value="{!f.name}" headerValue="Name"/>
<apex:column headerValue="Email" value="{!f.Email}"/>
<apex:column headerValue="Phone" value="{!f.phone}"/>
</apex:pageBlockTable>
</apex:form>
</apex:pageBlock>
 
</apex:page>
 
public class conrec1 {
public list<contact> l;
public string data{get;set;}
public list<contact> getdata1(){
l= [select name,email,phone from contact where name like: data + '%'];
system.debug(l);
return l;
}
    
}


 
Best Answer chosen by Deepak agarwal 9
Jayamaruthyraman JaganathJayamaruthyraman Jaganath
Here is something you can use:

The Visualforce page:
 
<apex:page controller="onDemandDetailsController">
<apex:pageBlock title="Search for the contact">
<apex:form >
<apex:inputText value="{!data}"/>
<apex:commandButton value="Search"/>
<apex:pageBlockTable title="Contact" var="f" value="{!data1}" columns="4">
<apex:column value="{!f.name}" headerValue="Name"/>
<apex:column >
    <apex:commandButton reRender="contactDetails" value="Details">
        <apex:param name="id4" value="{!f.id}" assignTo="{!id1}" />
    </apex:commandButton> 
</apex:column>
<apex:column headerValue="Email" value="{!f.Email}"/>
<apex:column headerValue="Phone" value="{!f.phone}"/>
</apex:pageBlockTable>
</apex:form>
<hr/>

</apex:pageBlock>


 <apex:outputPanel id="contactDetails">
<apex:outputLabel value="{!id1}"></apex:outputLabel>

<apex:detail subject="{!id1}" />
</apex:outputPanel>
</apex:page>

The controller code:
 
public with sharing class onDemandDetailsController {
    
    public Id id1 { set; get; }
 
public list<contact> l;
public string data{get;set;}
public list<contact> getdata1(){
    l= [select id, name,email,phone from contact where name like :data + '%'];
    system.debug(l);
    return l;
}
    
}

 

All Answers

Jayamaruthyraman JaganathJayamaruthyraman Jaganath
Here is something you can use:

The Visualforce page:
 
<apex:page controller="onDemandDetailsController">
<apex:pageBlock title="Search for the contact">
<apex:form >
<apex:inputText value="{!data}"/>
<apex:commandButton value="Search"/>
<apex:pageBlockTable title="Contact" var="f" value="{!data1}" columns="4">
<apex:column value="{!f.name}" headerValue="Name"/>
<apex:column >
    <apex:commandButton reRender="contactDetails" value="Details">
        <apex:param name="id4" value="{!f.id}" assignTo="{!id1}" />
    </apex:commandButton> 
</apex:column>
<apex:column headerValue="Email" value="{!f.Email}"/>
<apex:column headerValue="Phone" value="{!f.phone}"/>
</apex:pageBlockTable>
</apex:form>
<hr/>

</apex:pageBlock>


 <apex:outputPanel id="contactDetails">
<apex:outputLabel value="{!id1}"></apex:outputLabel>

<apex:detail subject="{!id1}" />
</apex:outputPanel>
</apex:page>

The controller code:
 
public with sharing class onDemandDetailsController {
    
    public Id id1 { set; get; }
 
public list<contact> l;
public string data{get;set;}
public list<contact> getdata1(){
    l= [select id, name,email,phone from contact where name like :data + '%'];
    system.debug(l);
    return l;
}
    
}

 
This was selected as the best answer
Deepak agarwal 9Deepak agarwal 9
Thanks a lot it hepled me!!