+ Start a Discussion
ishchopraishchopra 

Very Basic Problem

Hello Everyone,

 

Below is my controller and VF page but for some reason it is not showing me the related contacts. Can you please advice?

 

 

 

Apex Class:

 

public with sharing class Second
{
public Account AC{ get; set; }  
public List<Contact> CI{ get; set; }

public second()
{
AC= new account();
CI = new list<Contact>();
}
public pagereference FindContacts()

{

    CI = [SELECT FirstName, LastName FROM Contact WHERE AccountId = :AC.parentid];

return null;
            
}
}

 

==================================================================================

 

VF:

 

 

<apex:page controller="Second">
<apex:form >

            <apex:pageBlock Title="Select Account">
                 <apex:inputField value="{!AC.parentid}"/>

<apex:commandButton action="{!FindContacts}" value="FindContacts" reRender="contacts"/>
                 
               </apex:pageblock>

<apex:pageblock id="Contacts" Title="Contacts" >
<apex:pageBlockTable value="{!CI}" var="AB" >

                         <apex:column value="{!AB.firstName}"/>
                        <apex:column value="{!AB.lastname}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

 

I am new to the VF and if somebody can explain the "Contacts" above in bold used in reRender and <apex:pageblock id="Contacts" Title="Contacts" > then it will really help me to focus on right direction.

 

waiting for the replies

 

thankyou so much for looking

 

ish

Best Answer chosen by Admin (Salesforce Developers) 
ishchopraishchopra

Hello,

 

The problem is solved, it was really a basic problem

 

 

--------------------------------------------------------------------------------------------------

<apex:commandButton action="{!FindContacts}" value="FindContacts" reRender="contacts"/>
                 
               </apex:pageblock>

<apex:pageblock id="Contacts" Title="Contacts" >

--------------------------------------------------------------------------------------------------

 

if you notice Contacts in the first line its starting letter is in lower case and this is case sensitive, i have changed first line contacts to Contacts and it worked

 

Thanks

 

All Answers

Starz26Starz26

rerender is case sensitive..

 

change it to Contacts..

 

You might also have to use a different variable as IIRC using IDs that are also object names has caused me an issue before.

 

Also, instead of Account.parentID, you could use contact.AccountID for the inputfield...

ishchopraishchopra

Hello,

 

thanks for the reply, i have tried all three things which you have asked but nothing working.

 

changed reRender spelling

changed it back to contacts

Tried using Contact.AccountID

 

but it is still the same no result when clicking 'Find contacts' button

 

please help

ishchopraishchopra

Hello,

 

The problem is solved, it was really a basic problem

 

 

--------------------------------------------------------------------------------------------------

<apex:commandButton action="{!FindContacts}" value="FindContacts" reRender="contacts"/>
                 
               </apex:pageblock>

<apex:pageblock id="Contacts" Title="Contacts" >

--------------------------------------------------------------------------------------------------

 

if you notice Contacts in the first line its starting letter is in lower case and this is case sensitive, i have changed first line contacts to Contacts and it worked

 

Thanks

 

This was selected as the best answer
Starz26Starz26

thanks for the reply, i have tried all three things which you have asked but nothing working.

 

changed reRender spelling

 

please help


No, not the spelling of reRender, the spelling of the ID (contatcs) that you are rerendering........