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
srutmsrutm 

display list of all records of my custom object in visual force page

I have my custom object,with records,i need all my records to be  displayed in my visual force page... when i click on button listrecords...

LakshmanLakshman

you can try doing as below:

 

Apex :

public Boolean showRecords{get;set;}
public List<CustomObject__c> cust {get;set;}
//In constructor
showRecords =false;
public void fetchRecords(){ cust = [Select Field1__c, Field2__c from CustomObject__c limit 1000];// you need to place a limit of 1000 as VF supports max of 1000 recors to be displayed
showRecords = true;
}

 

 

VFP:

<apex:pageblock>
<apex:commandButton value="List Records" action="{!fetchRecords}" rerender="pbTable"/> <apex:pageblocktable value="{!cust}" var="a" id="pbTable" rendered="{!showRecords}"> <apex:column value="{!a.Field1__c}"/> <apex:column value="{!a.Field2__c}"/> </apex:pageblocktable > </apex:pageblock>

 

Let me know if it works for you.

 

Regards,

Lakshman

 

 

Sai Sasidhar BhagavathulaSai Sasidhar Bhagavathula
Hi,

I am trying to diplay the records in VF Page as is shown above, but unable to fetch records from SOQL.
Could you please help me out.

Thank you in Advance !

public class CustomControllerView {    
    public List<Test__c> test{set;get;}    
    public void ControllerView(){        
        test = new List<Test__c>(); 
        test = [SELECT Id,Name,TestPhone__c FROM Test__c LIMIT 10]; 
        system.debug('@@@' + test);
    }
 }    

 
Deepali KulshresthaDeepali Kulshrestha
Hi Srutm,

- I read your problem and implemented it in my Org and it is working fine.
- Please use the below code and customize as per your need: -
-------------- Apex Controller------- -----
public class Records
{
    public List<Student__c> StudentRecords {get;set;}
    public void search()
        {
            StudentRecords = [SELECT Name,Email__c,Phone__c FROM Student__c LIMIT 100];
        }
}
----------------VF Page-------------------

<apex:page controller = "Records">
    <apex:form>
        <apex:pageBlock>
            <apex:commandButton value = "records" action = "{!search}"/>
                <apex:pageBlockTable value="{!StudentRecords}" var = "stu">
                    <apex:column value = "{!stu.Name}"/>
                    <apex:column value = "{!stu.Email__c}"/>
                    <apex:column value = "{!stu.Phone__c}"/>
                </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha.
asif jamal 21asif jamal 21
How we can add edit functionlity in this type of list. someone plz help.
prahlad bandhuprahlad bandhu
Hi Asif
Visualforce Page (EditRecordsPage (http://salesforce.com/trailblazer/prahladbandhu)):
<apex:page controller="EditRecordsController">
    <apex:form>
        <apex:pageBlock title="Edit Records">
            <apex:pageBlockTable value="{!records}" var="record">
                <apex:column headerValue="Name">
                    {!record.Name}
                </apex:column>
                <!-- Add more columns for other fields as needed -->
                <apex:column>
                    <apex:commandButton value="Edit" action="{!editRecord}">
                        <apex:param name="recordId" value="{!record.Id}" assignTo="{!recordId}" />
                    </apex:commandButton>
                </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

EditRecordsController

public with sharing class EditRecordsController {
    public CustomObject__c record { get; set; }
    public String recordId { get; set; }

    public EditRecordsController() {
       
        record = [SELECT Id, Name /* Add other fields */ FROM CustomObject__c WHERE Id = :recordId LIMIT 1];
    }

    public PageReference editRecord() {
       
        PageReference editPage = Page.EditRecordPage; 
        editPage.getParameters().put('recordId', recordId);
        return editPage;
    }
}

EditRecordPage

<apex:page controller="EditRecordController">
    <apex:form>
        <apex:pageBlock title="Edit Record">
            <apex:pageBlockSection columns="1">
                <apex:inputField value="{!record.Name}" label="Name" />
                <!-- Add more fields for other record details as needed -->
            </apex:pageBlockSection>
        </apex:pageBlock>
        <apex:commandButton value="Save" action="{!saveRecord}" />
    </apex:form>
</apex:page>


EditRecordController (https://salesforce.com/trailblazer/prahladbandhu)

public with sharing class EditRecordController {
    public CustomObject__c record { get; set; }
    public String recordId { get; set; }

    public EditRecordController() {
       
        record = [SELECT Id, Name /* Add other fields */ FROM CustomObject__c WHERE Id = :recordId LIMIT 1];
    }

    public PageReference saveRecord() {
        
        update record;

        
        PageReference listPage = Page.EditRecordsPage; 
        return listPage.setRedirect(true);
    }
}

Thanks 
Prahlad Bandhu (https://salesforce.com/trailblazer/prahladbandhu)