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
vcvvcv 

Custom object form and list of records

Hi,

I have a beginner's problem:

I have a custom object (Candidates) with a VF page that overrides the standard form. Underneath there should be a list of records already submitted through the form. My code displays the form correctly, yet the list shows up empty. If i save a form entry, it appears in the list but disappears on refresh.  Is it possible to fix this issue exclusively in VF?

Here is the code:
<apex:page standardController="Candidates__c">
    <apex:form id="theForm">

    <apex:pageBlock title="Enter candidate">
            <apex:pageBlockSection columns="2">
                <apex:inputfield value="{!Candidate__c.FirstName__c}"/>
                <apex:inputfield value="{!Candidate__c.LastName__c}"/>                
            </apex:pageBlockSection>
     </apex:pageBlock>
           
<apex:pageBlock title="List of Candidates">
   <apex:pageBlockTable value="{!Candidates__c}" var="candidates">
      <apex:column value="{!candidates.FirstName}"/>
      <apex:column value="{!candidates.LastName}"/>
   </apex:pageBlockTable>
</apex:pageBlock>

        </apex:form>
    </apex:page>

 
Best Answer chosen by vcv
SandhyaSandhya (Salesforce Developers) 
Hi,

Try with below code which worked for me.
 
<apex:page standardController="Candidates__c" recordSetVar="Candidates">
    <apex:form id="theForm">

    <apex:pageBlock title="Enter candidate">
            <apex:pageBlockSection columns="2">
                            <apex:inputfield value="{!Candidates__c.FirstName__c}"/>                

                <apex:inputfield value="{!Candidates__c.LastName__c}"/>                
            </apex:pageBlockSection>
     </apex:pageBlock>
           
<apex:pageBlock title="List of Candidates">
  <apex:pageBlockTable value="{!Candidates}" var="a" id="list">

        <apex:column value="{!a.FirstName__c}"/>
                <apex:column value="{!a.LastName__c}"/>


      </apex:pageBlockTable>
</apex:pageBlock>

        </apex:form>
    </apex:page>

Please mark it as solved if my reply was helpful, it will make it available
for others as a proper solution.

Best Regards,
​Sandhya
 

All Answers

SandhyaSandhya (Salesforce Developers) 
Hi,

Try with below code which worked for me.
 
<apex:page standardController="Candidates__c" recordSetVar="Candidates">
    <apex:form id="theForm">

    <apex:pageBlock title="Enter candidate">
            <apex:pageBlockSection columns="2">
                            <apex:inputfield value="{!Candidates__c.FirstName__c}"/>                

                <apex:inputfield value="{!Candidates__c.LastName__c}"/>                
            </apex:pageBlockSection>
     </apex:pageBlock>
           
<apex:pageBlock title="List of Candidates">
  <apex:pageBlockTable value="{!Candidates}" var="a" id="list">

        <apex:column value="{!a.FirstName__c}"/>
                <apex:column value="{!a.LastName__c}"/>


      </apex:pageBlockTable>
</apex:pageBlock>

        </apex:form>
    </apex:page>

Please mark it as solved if my reply was helpful, it will make it available
for others as a proper solution.

Best Regards,
​Sandhya
 
This was selected as the best answer
Ajay K DubediAjay K Dubedi
Hi vcv,

Check If this can solve your issue:
<apex:page standardController="Candidates__c" recordSetVar="Candidates">
    <apex:form id="theForm">
        
        <apex:pageBlock title="Enter candidate">
            <apex:pageBlockSection columns="2">
                <apex:inputfield value="{!Candidates__c.First_Name__c}"/>                
               <apex:inputfield value="{!Candidates__c.Last_Name__c}"/>                          
            </apex:pageBlockSection>
        </apex:pageBlock>
        
        <apex:pageBlock title="List of Candidates">
            <apex:pageBlockTable id="PbID" value="{!Candidates}" var="Can" >
                
                <apex:column value="{!Can.First_Name__c}"/>
                <apex:column value="{!Can.Last_Name__c}"/>

            </apex:pageBlockTable>
        </apex:pageBlock>
        
    </apex:form>
</apex:page>

Thank you 
Ajay Dubedi
vcvvcv
Hi again,

thanks for helping out - I will give it a try and mark as solved. Just another question - is there a way to simply add save button to the form AND a delete button to the list of records so that it is possible to delete a candidate?
vcvvcv
Hi,

both codes above work fine. Except some issues:
- I can add the VF page to the page tab, not the New button
- if I try to save an entry, it redirects me to the platform's first page (in my dev page) and does not show a new entry in the list of records