+ Start a Discussion
Siva Sankar PaluriSiva Sankar Paluri 

Unable to display results on VF page (Records obtained from Apex Class)

I have below Apex class , returning Id and Name based on the given condition.(Able to see the values in Debug Log)

public class NewJobPostings
public static void getpostdetails()


NewJobPostings__c NJP = New NewJobPostings__c(); 
NJP = [Select id,Name from NewJobPostings__c where  Job_Status__c=true]; 



Used this controller in VF page to display the records on VF page which are obtained from Apex class. But unable to do so. Can any one please guide

<apex:page Controller="NewJobPostings">

<apex:form >
<apex:pageBlock >

<apex:pageBlockSection >

<apex:outputField value="{!NJP.Name}"/>




Khan AnasKhan Anas (Salesforce Developers) 
Hi Siva,

Modify your Controller code as below:
public class NewJobPostings {
    public NewJobPostings__c njp {get;set;}
    public NewJobPostings() {
        njp = new NewJobPostings__c();
        njp = [SELECT Id, Name FROM NewJobPostings__c WHERE Job_Status__c = true LIMIT 1];   

You are using <apex:outputField> you have to limit your query to 1. If you want more records whose Job_Status__c is true then you have to use <apex:pageBlockTable>

I hope it helps you.

Kindly let me inform if it helps you and close your query by marking it as solved so that it can help others in future.

Thanks and Regards,
Khan Anas​
Siva Sankar PaluriSiva Sankar Paluri
Thank you Anas, it worked.
Khan AnasKhan Anas (Salesforce Developers) 
Hi Siva,

It's my pleasure. I’m glad I was able to help!

Kindly mark this as solved if it's resolved so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue.

Khan Anas