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
Kunal Purohit 4Kunal Purohit 4 

How to create a Visualforce page with One field?

Hello Folks,
I am learning VisualForce page. I want to create a VF page with one field and this page should make the api call/fetch the data from custom object and show it in that field. I have tried with below code but it is generating an error: 

Unknown property 'ZipCodeController.ProspectUser__c'

Here ProspectUser__c is an object name and ZipCode__c is a field name.

VF Page:

<apex:page controller ="ZipCodeController" >
    
    <apex:form>
    <apex:inputField value = "{!ProspectUser__c.ZipCode__c}"/>
    </apex:form>
</apex:page>


Controller:
public with sharing class ZipCodeController {
	
    public List<ProspectUser__c> getProspectUser{get;set;}
    
    public ZipCodeController()
    {
        getProspectUser = [Select ZipCode__c FROM ProspectUser__c LIMIT 1];
    }
    
}
 

Please suggest.

Sai PraveenSai Praveen (Salesforce Developers) 
Hi Kunal,

The Vf page and Apex class can be as below.

Vf Page:
<apex:page standardController="Account"  extensions="showAccount"> >
       <apex:form>
    <apex:inputField value = "{!acclist[0].name}"/>
    </apex:form>
</apex:page>

Apex:
public class showAccount {
public List<Account> acclist {set;get;}


public showAccount(ApexPages.StandardController controller)
     {

        fetchaccList();
     }
       public void fetchaccList(){
      
    
        acclist =[select Name  from Account  limit 1];

        
        }
}

Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,
H 007H 007
To create a Visualforce page with one field in Salesforce, you can follow these steps:
  • Go to Setup > Develop > Pages.
  • Click on the "New" button.
  • In the "Label" field, enter a name for the page.
  • In the "Name" field, enter a unique name for the page (this will be used in the URL).
  • In the "Markup" section, enter the following code:
  • <apex:page >
        <apex:form >
            <apex:inputField value="{!ObjectName.FieldName}" />
        </apex:form>
    </apex:page>
    Replace "ObjectName" and "FieldName" with the actual object and field names that you want to display on the page.
    Click "Save".
    You can also add other components to the page like input text, output text and action support or command button to submit the form data.
    When you navigate to the page, you will see the input field for the specified field of the specified object. You can also customize the look and feel of the page by using Salesforce's Visualforce markup language and CSS.