
any help will be greatly appreciated.
ThanksPoojaglobal class remotingexample
{
public String accountName { get; set; }
public static Account account { get; set; }
public remotingexample() { }
@RemoteAction
webservice static Account getAccount(String accountName)
{
account = [select id, name from Account where name=:accountName ];
return account;
}
}
<apex:page controller="remotingexample">
<script type="text/javascript">
function getAccountJS()
{
var accountNameJS = document.getElementById('accName').value;
sample.getAccount( accountNameJS,
function(result, event)
{
if (event.status)
{
// demonstrates how to get ID for HTML and Visualforce tags
document.getElementById("{!$Component.theBlock.thePageBlockSection.theFirstItem.accId}").innerHTML = result.Id;
document.getElementById("{!$Component.theBlock.thePageBlockSection.theSecondItem.accNam}").innerHTML = result.Name;
}
else if (event.type === 'exception')
{
document.getElementById("errors-js").innerHTML = event.message;
} else
{
document.getElementById("errors-js").innerHTML = event.message;
}
}, {escape:true});
}
</script>
Account Name :<input id="accName" type="text" />
<button onclick="getAccountJS()">Get Account</button>
<div id="errors-js"> </div>
<apex:pageBlock id="theBlock">
<apex:pageBlockSection id="thePageBlockSection" columns="2">
<apex:pageBlockSectionItem id="theFirstItem">
<apex:outputText id="accId"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem id="theSecondItem" >
<apex:outputText id="accNam" />
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:page>
hi,try using this when you get result. "result.getArray(“records”);". You get associative array. You can not just use result.Id etc.try to debug in console.log(); and let me know if it helps.