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
Gopesh Vardhan SinghGopesh Vardhan Singh 

Error in VF page

created 2 custom objects.  ACCOUNT TPYE AND CONTACTS

Contact has accounttype field which is in lookup relationship with name field of ACCOUNTTYPE custom object

sUPPOSE i have 10 obects in contacts list..
and i wants to filter the contact details on the basis of contact.accounttype

Logic is

Cout<<"Enter Value of Account Type.."
Cin>>var;

For(i=0;i<10;i++)
{
if(contact.account == var)
   {

cout<"Contact name = "<<contact.name;
cout<"Contact email = "<<contact.email;
cout<"Contact phone no. = "<<contact.phone;
cout<"Contact position. = "<<contact.positiion;  
}

}

what will be the code in VF page
Amritesh SahuAmritesh Sahu
Hi Gopesh,

You need to create a controller class for the vf page.
For VF
<apex:page controller="mycontroller">
<apex:form>
  <apex:outputLabel value="Enter Account Name : "/>
  <apex:inputText value="{!AccountName}" />
  <apex:commandButton value="Fetch Contacts" action="{!fetch}"/>
  <apex:pageBlock title="Contacts of {!AccountName}">
    <apex:pageBlockTable value="{!contactlist}" var="con">
      <apex:column value="{!con.name}" headerValue="Contact Name"/>
    </apex:pageBlockTable>
  </apex:pageBlock> 
</apex:form>
</apex:page>
Controller Class
public class mycontroller {

    Public String AccountName{get;set;}
    Public List<Contact__c> contactlist {get;set;}
    
    Public mycontroller()
    {
        contactlist = new List<Contact__c>();
    }
    
    Public void fetch()
    {
        if(AccountName!='')
        contactlist = [select id,name from Contact__c where account_type__r.name=:AccountName];
    }

}
Please modify the API name of Contact and Account as your requirement.

Thanks
Amritesh