+ Start a Discussion
sultansultan 

Hi community How to display record name if I pass id's to the controller using a vf page?please send the code?

Best Answer chosen by sultan
Vidhyasagaran MuralidharanVidhyasagaran Muralidharan
VF page:
<apex:page Controller="Account">
<apex:form>
<apex:inputtext value="{!accountid}"/> <p/>
<apex:pageBlock title="My account detail">
<apex:pageBlockTable value="{!a}" var="item">
<apex:column value="{!item.number}"/>
<apex:column value="{!item.name}"/>
<apex:column value="{!item.phone}"/>
//other details depend on requirement
</apex:pageBlockTable
<apex:commandButton value="display" action="{!display}"/>
</apex:form>
</apex:page>
Controller:
Public class display details{
String accountid{get;set;}
List<Account> a{get;set;}
Public display details()
{
a=new <Account>();
}
Public void display()
{
a.clear();
Account b=[Select number,name,phone from Account where Accountid:accountid LIMIT 1];
a.add(b);
}
}

It is general just to give you idea i typed this code.use this as base code and change it according to your requirement

All Answers

Sagar PareekSagar Pareek
Hi Raju, It would be great if you can post some code here that you tried .

Please have a look at this link
http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_extension.htm
Hargobind_SinghHargobind_Singh
Hi Raju,

You can use the following sample code. Customize it for your own needs, and also add some exception handling. 

ID id1 = ApexPages.CurrentPage().getParameters().get('id'); 
String sObjName = id1.getSObjectType().getDescribe().getName();
String query1 = 'select name from ' + sObjName + ' where id = :id1 limit 1'; 
SObject[] s = Database.query(query1); 
String name1 = ''; 
if(s.size()>0){
	name1 = (String) s[0].get('name'); 
}
System.debug(name1);


Vidhyasagaran MuralidharanVidhyasagaran Muralidharan
VF page:
<apex:page Controller="Account">
<apex:form>
<apex:inputtext value="{!accountid}"/> <p/>
<apex:pageBlock title="My account detail">
<apex:pageBlockTable value="{!a}" var="item">
<apex:column value="{!item.number}"/>
<apex:column value="{!item.name}"/>
<apex:column value="{!item.phone}"/>
//other details depend on requirement
</apex:pageBlockTable
<apex:commandButton value="display" action="{!display}"/>
</apex:form>
</apex:page>
Controller:
Public class display details{
String accountid{get;set;}
List<Account> a{get;set;}
Public display details()
{
a=new <Account>();
}
Public void display()
{
a.clear();
Account b=[Select number,name,phone from Account where Accountid:accountid LIMIT 1];
a.add(b);
}
}

It is general just to give you idea i typed this code.use this as base code and change it according to your requirement
This was selected as the best answer