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
AduttAdutt 

actionFunction method is not working..

Hi All,

I have a custom VF page which performs the normal search functionality on Account and based on the selected account value wants to proceed further.

Problem:

I am not able to pass the selected account's id as action function is not working in the following code:

 

<apex:page controller="accountSearch">
<apex:form >
<script>
function toGetAccountId(id)
{
alert('test1');
variable1=document.getElementById(id).value;
xyz(variable1);
alert('test2');
}
</script>

<apex:pageBlock >


<apex:actionFunction name="xyz" action="{!samepage}">  

   <apex:param value="" assignTo="{!var1}"/>

</apex:actionFunction>



<apex:outputLabel value="Enter your search text:" >
<apex:inputText value="{!searchVar}">
</apex:inputText>
</apex:outputLabel>

<apex:commandLink value="Search" action="{!getAccounts}" />

<apex:pageBlockTable value="{!accList}" var="acc">
<apex:column headerValue="Account Name" > <apex:outputLink id="olId" onclick="toGetAccountId('{!$Component.olId}')">{!acc.name}
</apex:outputLink></apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

-----------------------------------------------------

controller:

public with sharing class accountSearch {

public String olId { get; set; }
public String searchVar { get; set; }
public String var;
public String var1{get;set;}
public String var2;
public list<Account> accList = new list<Account>();

public PageReference getAccounts() {
var='%'+searchVar+'%';
system.debug('aaaaaaaaaaaa'+var);
accList = [Select name,NumberOfEmployees from account where name LIKE:var ];
system.debug('vvvvv'+accList);
return null;
}

public list<Account> getAccList(){
return accList;
}
public pagereference samepage()
{
//PageReference curPage = ApexPages.currentPage();
system.debug('lllllllllll');
var2=var1;
system.debug('dddddddddddddd'+var2);
PageReference curPage = new Pagereference('/apex/testpage2');
curPage.setRedirect(true);
return curPage ;
}
}

 

After the list of accounts returned, if I select a particular account (onclick of a output link),the javascript is getting invoked and I am getting the alerts. But the action method (samepage()) is not invoked. (for testing purpose, I am just redirecting a test page on the action method and its not working)

Also, if I try saving <apex:actionFunction name="xyz" action="{samepage}"> instead of  <apex:actionFunction name="xyz" action="{!samepage}"> , its getting saved which is wrong

 

I am at lost. Please help..

 

Thanks.

 

 

 

nileshjnileshj

Hi Adutt,

 

Try rerender or call oncomplete() in apex:action function.

This might help you.

 

If this resloved your proble, please mark this answer as solution.

 

 

Thanks,

Nilesh.

 

Bhawani SharmaBhawani Sharma
<apex:actionFunction name="xyz" action="{!samepage}" immediate="true" reRender="test"/>