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
krishna chaitanya 35krishna chaitanya 35 

Javascript remoting to display a list of records in a pageblock or pageblock table

Hi ,
I tried to display list of accounts with searched name in the pageblock in visualforce using javascipt remoting.In the soql i am getting all the records but unable to display in the vf.Can anyone solve this puzzle.

apex:page
<apex:page controller="AccountRemoter">
<script type="text/javascript">
function getRemoteAccount() {
    var accountName = document.getElementById('acctSearch').value;

    Visualforce.remoting.Manager.invokeAction(
        '{!$RemoteAction.AccountRemoter.getAccount}',
        accountName,
        function(result, event){
            if (event.status) {
                // Get DOM IDs for HTML and Visualforce elements like this
                for(i=0;i<=result.length;i++){
                document.getElementById('remoteAcctId').innerHTML = result[i].Id
                document.getElementById(
                    "{!$Component.block.blockSection.secondItem.acctNumEmployees}"
                    ).innerHTML = result[i].NumberOfEmployees;
                    document.getElementById(
                    "{!$Component.block.blockSection.thirdItem.nameofacct}"
                    ).innerHTML = result[i].Name;
                    }
            } else if (event.type === 'exception') {
                document.getElementById("responseErrors").innerHTML =
                    event.message + "<br/>\n<pre>" + event.where + "</pre>";
            } else {
                document.getElementById("responseErrors").innerHTML = event.message;
            }
         },
         {escape: true}
     );
   }
  </script>

    <input id="acctSearch" type="text"/>
    <button onclick="getRemoteAccount()">Fetch Accounts</button>
    <div id="responseErrors"></div>

    <apex:pageBlock id="block">
    
    <apex:pageBlockSection id="blockSection" columns="3">
   
        <apex:pageBlockSectionItem id="firstItem">
            <span id="remoteAcctId"/>
        </apex:pageBlockSectionItem>
       
        <apex:pageBlockSectionItem id="thirdItem">
            <apex:outputText id="nameofacct"/>
        </apex:pageBlockSectionItem>
        
        <apex:pageBlockSectionItem id="secondItem">
            <apex:outputText id="acctNumEmployees"/>
        </apex:pageBlockSectionItem>
         
    </apex:pageBlockSection>
   </apex:pageBlock>
   </apex:page>

====class====
global with sharing class AccountRemoter {

public String accountName { get; set; }
public Account account { get; set; }
public AccountRemoter() {

}

@RemoteAction
global static List<Account> getAccount(String accountName) {

string strLikeString = '%'+accountName+'%';
        string strSOQL = 'select id,Name,NumberofEmployees from Account where name LIKE: strLikeString order by Name asc';
        List<Account> account = database.query(strSOQL);
   
return account;
}
}
krishna chaitanya 35krishna chaitanya 35
User-added image