Visualforce page:
<apex:page standardController="Account" showHeader="false" >
<apex:form >
<apex:pageBlock title="Account Detail">
<apex:pageblockSection title="Site Field Value" columns="1" collapsible="false">
<apex:inputText value="{! Account.Site}" id="gen"/>
<apex:actionPoller interval="5" action="{!siteValue}" reRender="gen" status="pollerStatus"/>
<apex:actionstatus startText="Updating Site values...." id="pollerStatus" ></apex:actionstatus>
<apex:pageBlockSectionItem >
</apex:pageBlockSectionItem>
</apex:pageblockSection>
<apex:pageBlock>
<apex:pageMessages ></apex:pageMessages>
</apex:pageBlock>
</apex:pageBlock>
=====controller class======
public with sharing class Account{
public List<Schema.Account> accountList = new List<Schema.Account>();
public Account(){
accountList = [select Site from Account];
}
public PageReference siteValue(){
if(Schema.Account.Site == null){
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'No value found'));
}
return null;
}
}
Thank you in advance.
Best Answer
In order to access methods of a custom apex class in a visualforce page, you should set that class as either the controller, or as one of the extensions on the page.
I should also add that in order for a class to be used as an extension, it must have a constructor that takes the StandardController as an argument. Also, you can't use
Account
as the name of your class since that apex class name already refers to the standard sObject, so your controller should be something like:Also,
Schema.Account.Site
gets the describe information for the Site field on Account. To get the value of the Site field on the Account that is referenced on the page, you should save a reference to the account from the controller when your apex class is constructed, and use that to determine the current value of Site field.Two more things, your error message still isn't showing up because: