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
umair ayazumair ayaz 

unknown property error please help

Hello I am trying to validate account name. I want to check if the account with same name exists so i have written controller class method to check it but i am not able to call it from visuaforce page.
Following is my visualforce page
<apex:page controller="AddAccountController" tabStyle="Account" standardStylesheets="false" showHeader="false" sidebar="false">
    <style>
        .myFormStyle {
        background-color: #D3D3D3;
        }
        .tableBorder
        {
        
        border:3px outset black;
        }
        .innerTableBorder{
        border-top:2px dotted black;
        border-left:2px dotted black;
        }
    </style>
    <script>
     function AccountCheck() {
         
         var x = "{!checkAccount}"
       alert(x);
        }
    </script>
    
    
    
    <apex:form styleClass="myFormStyle">
        <div>
            <apex:pageBlock title="Add Account">
                <apex:pageBlockButtons location="top" >                   
                    <apex:commandButton value="Save" action="{!save}" reRender="accountList"  />
                    <apex:commandButton value="Cancel" action="{!cancel}" />
                    
                </apex:pageBlockButtons>  
                <apex:pageBlockSection title="Account Details" columns="1">            
                    <apex:inputField id="accountName" value="{!act.name}" onblur="AccountCheck()"/> 
                    <apex:inputField value="{!act.site}"/> 
                    <apex:inputField value="{!act.type}"/> 
                    <apex:inputField value="{!act.accountNumber}"/>              
                </apex:pageBlockSection>         
            <apex:pageBlockTable value="{!Account}" var="acc" id="accountList" styleClass="tableBorder">              
                <apex:column value="{!acc.Name}" styleClass="innerTableBorder" />            
                <apex:column value="{!acc.Site}" styleClass="innerTableBorder" />               
                <apex:column value="{!acc.type}" styleClass="innerTableBorder" />               
            </apex:pageBlockTable>
        </apex:pageBlock>
    </div>
</apex:form>
</apex:page>

Here on its my Controller
 
public class AddAccountController {
    
    public List <Account> account=new List <Account>();
    public Account act{get;set;}
    public integer counter {get;set;}
    
    public AddAccountController() {       
        act = new Account();
        this.counter=0;
    }
    
    public List <Account> getAccount() {
        account = [SELECT Id, Name, Site, Type FROM Account order by createddate desc limit 20];
        return account;
    }
    
    public PageReference cancel() {
        return null;
    }
    
    public PageReference save() {
        system.debug('act name:' + act.name + ' = ' + act.accountNumber);
        upsert act;
        return null;
    }
    public Integer checkAccount(){
        String accountName =System.currentPageReference().getParameters().get('accountName');
        account = [SELECT Id, Name, Site, Type FROM Account WHERE Name = :accountName];
        if(account.size()>0){
            counter=1;
            return counter;
        }
        return counter;
    }
}
Below is the error that i get please tell me why i get this error.
Unknown property 'AddAccountController.checkAccount'
I want it to call the checkAccount() method  from my javasccript function that i am calling from onblur method. So please experts help a newbie
 
Raj VakatiRaj Vakati
Hi ,

You need to use Action function or other Salesforce javascript option. the way you are invoking the code was wrong.
You can not call the Salesforce controller action directly into the javascript . 



Thanks ,
Raj