You need to sign in to do that
Don't have an account?
rohitsfdc
using List for storing data
Hi,
i created a child object for contact. In this child contact i am using getter for childContact to retrieve information in visualforce page. the problem is, everytime i add this information to a list, it only displays the latest information entered, not previous values
<apex:page standardController="childContact__c" extensions="childContact" >
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:inputField value="{!childContac.Date_Graduated__c}"/>
<apex:inputField value="{!childContac.Date_Started__c}"/>
<apex:inputField value="{!childContac.favorite_professor__c}"/>
<apex:inputField value="{!childContac.School_attended__c}"/>
</apex:pageBlockSection>
<apex:pageBlockButtons location="bottom" ><apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:pageBlockButtons>
</apex:pageBlock>
<apex:pageBlock >
<apex:pageBlockSection >
<apex:pageblockTable value="{!fetchTable}" var="fetch" >
<apex:column value="{!fetch.Date_Started__c}" />
<apex:column value="{!fetch.Date_Graduated__c}"/>
<apex:column value="{!fetch.favorite_professor__c}"/>
<apex:column value="{!fetch.School_attended__c}"/>
</apex:pageblockTable>
....
....
....
and the extention for this is
public with sharing class childContact { public childContact(ApexPages.StandardController controller) {} ID id2=apexPages.currentPage().getParameters().get('rid'); List<childContact__c> listContact= new List<childContact__c>(); public childContact__c childContac { get { if(childContac ==null) childContac = new childContact__c(); return childContac ; } set; } public PageReference Save() { childContac.contact__c=id2; listContact.add(childContac); return null; } public List<childContact__c> fetchTable { get{ return listContact; } set; }}
please tell me where am i doing it wrong, or where do i need modification.
I think the problem here is that you aren't creating a new child contact after you've added to this list, so you are effectively overwriting the values each time.
Try changing your save method to: