You need to sign in to do that
Don't have an account?
Remoting method not getting called.
Here is my VF Page and below is my code.
When i try to run this only alert1 & 2 & 3 r getting called but the method in the controller is not getting invoked.
Please help what i m missing.
<apex:page controller="RemoteController" id="thePage">
<apex:form id="theForm" >
<apex:pageBlock id="theBlock" >
<apex:pageblockSection columns="1" id="searchSection">
<apex:pageBlockSectionItem id="item" >
<apex:inputText id="searchBox" />
<input type="button" value="Search" onclick="getRemoteAccount()"/>
</apex:pageBlockSectionItem>
</apex:pageblockSection>
</apex:pageBlock>
</apex:form>
<script type="text/javascript">
function getRemoteAccount() {
var accountName = document.getElementById('thePage:theForm:theBlock:searchSection:item:searchBox').value;
alert('1')
Visualforce.remoting.Manager.invokeAction( '{!$RemoteAction.RemoteController.getAccount}', accountName,
function(result, event){
var account = result[0];
alert('2')
if(account==null)
alert('3')
alert(account.Name);
if (event.status) {
// document.getElementById('acctId').innerHTML = result.Id
// document.getElementById('acctName').innerHTML = result.Name;
}
else if (event.type === 'exception') {
//document.getElementById(“responseErrors").innerHTML = event.message;
alert(event.message);
}
else {
// document.getElementById(“responseErrors").innerHTML = event.message;
alert(event.message);
}
},
{escape: true}
);
}
</script>
</apex:page>
****
public class RemoteController {
public RemoteController(){
}
@RemoteAction
public static List<Account> getAccount(String accName) {
System.Debug('Hello');
List<Account> lstAcc = [select id,name from Account where name =:accName];
if(!lstAcc.isEmpty()){
return lstAcc;
}
return new List<Account>();
}
}
Thanks
Sai
Hi,
Your code seems write which you have posted here.
Also you can compare with this code as follows :
According to above code i am able to get alert with account name if there is an account with matched name else get no match found alert.
So might be possible your code is not working due to any other part of code. I can help you if you post the exact code.
Please mark it as solution if it works for you.
Thanks
Vikash Goyal
All Answers
Hi,
Your code seems write which you have posted here.
Also you can compare with this code as follows :
According to above code i am able to get alert with account name if there is an account with matched name else get no match found alert.
So might be possible your code is not working due to any other part of code. I can help you if you post the exact code.
Please mark it as solution if it works for you.
Thanks
Vikash Goyal