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
Sachin10Sachin10 

Unable to pass parameter using Action Function

Hi,

For some odd reason, I'm unable to pass the parameter using APEX:ACTIONFUNCTION.

 

Code Snippet:

 

VF PAGE:

<apex:page standardController="Service_Catalogue__c" extensions="serviceCatalogueCtrl">

<script>
function fnChange(a)
{
alert('Hello Param'+a);
testJs(a);
alert(a);
}

<apex:form>

<apex:actionFunction name="testJs" action="{!testJs}" rerender="" >
<apex:param value="" id="y" assignTo="{!subCategory}" />
</apex:actionFunction>

 

<apex:inputField value="{!Service_Catalogue__c.Category__c}"/>
<apex:inputField value="{!Service_Catalogue__c.SubCategory__c}" onchange="fnChange(this.value);" />

</apex:form>

</apex:page>

 

APEX CLASS:

public class serviceCatalogueCtrl {

 public string subCategory{get;set;}

public serviceCatalogueCtrl(ApexPages.StandardController controller) {
}

public PageReference testJs()
{
system.debug('Hello subCategory @@'+subCategory);

return null;
}

}

 

 

Service catalogue is my custom object which has 2 picklist fields category and subcategory.

I want to pass the value that I selected in subcategory field and pass it to my controller for further processing.

 

But for some reason subcategory value is not getting set while trying to set in actionfunction.

 

It looks simple but I'm missing something.

Many thanks in advance for your help:)

Thank You!

 

Best Answer chosen by Admin (Salesforce Developers) 
Grazitti InteractiveGrazitti Interactive

Hi,

 

Try following code, I have tested its working.

Please Change Account to your custom object and input in both input field.

 

VF Page:

 

<apex:page standardController="Account" extensions="serviceCatalogueCtrl">
<script>
function fnChange(a)
{

// first make sure 'a ' is not null here
alert('Hello Param'+a);
testJs(a);
alert(a);
}
</script>
<apex:form>
<apex:actionFunction name="testJs" action="{!testJs}" rerender="" >

<apex:param name="param" value="" id="y" assignTo="{!subCategory}" />
</apex:actionFunction>

<apex:inputField value="{!Account.Name}"/>

<!--if this field is picklist then use 
<apex:inputField value="{!Account.Name}" onchange="fnChange(this.value);" />
</apex:form>
</apex:page>

 

Apex class:

 

public class serviceCatalogueCtrl {
public string subCategory{get;set;}
public serviceCatalogueCtrl(ApexPages.StandardController controller) {
}
public PageReference testJs()
{
system.debug('Hello subCategory @@'+subCategory);
return null;
}
}

/**If this post helps you then please mark it as a solution and don't forget to give me kudo's by clicking star aside.***/

 

Thanks,

www.grazitti.com

All Answers

Grazitti InteractiveGrazitti Interactive

Hi,

 

Try following code, I have tested its working.

Please Change Account to your custom object and input in both input field.

 

VF Page:

 

<apex:page standardController="Account" extensions="serviceCatalogueCtrl">
<script>
function fnChange(a)
{

// first make sure 'a ' is not null here
alert('Hello Param'+a);
testJs(a);
alert(a);
}
</script>
<apex:form>
<apex:actionFunction name="testJs" action="{!testJs}" rerender="" >

<apex:param name="param" value="" id="y" assignTo="{!subCategory}" />
</apex:actionFunction>

<apex:inputField value="{!Account.Name}"/>

<!--if this field is picklist then use 
<apex:inputField value="{!Account.Name}" onchange="fnChange(this.value);" />
</apex:form>
</apex:page>

 

Apex class:

 

public class serviceCatalogueCtrl {
public string subCategory{get;set;}
public serviceCatalogueCtrl(ApexPages.StandardController controller) {
}
public PageReference testJs()
{
system.debug('Hello subCategory @@'+subCategory);
return null;
}
}

/**If this post helps you then please mark it as a solution and don't forget to give me kudo's by clicking star aside.***/

 

Thanks,

www.grazitti.com

This was selected as the best answer
Sachin10Sachin10

@

 Have you got that printed in the system debug?

 

The below system debug line is displayed as null to me.

system.debug('Hello subCategory @@'+subCategory);

 

Did you get the selected value of the picklist?

 

 

nickwick76nickwick76

Hi, 

In what way are you unable? 

If it compiles but you get nothing, then my guess is that it's because the value is empty.

 

<apex:param value="" id="y" assignTo="{!subCategory}" />

Suggesting:
<apex:param value="something else" id="y" assignTo="{!subCategory}" />

value can also be dynamic content

 HTH / Niklas

Sachin10Sachin10

@nickwick thanks for your reply...

 

I'm missing the name attribute while using the apex:param tag.So that i s causing the problem.

Although i'm not sure why we require the name attribute, it is what causing the problem.

 

If anyone knows the reason, please enlighten me on what is the need for name attribute.

 

Thank You!

 

 

Grazitti InteractiveGrazitti Interactive

Hi Sachin,

 

yes, I got value in debug as following. Please use same code just by replacing object name and field name that I have given .

 

28.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
16:05:35.046 (46661000)|EXECUTION_STARTED
16:05:35.046 (46708000)|CODE_UNIT_STARTED|[EXTERNAL]|06690000002wvCT|VF: /apex/dabur__testForum
16:05:35.049 (49641000)|VF_DESERIALIZE_VIEWSTATE_BEGIN|06690000002wvCT
16:05:35.056 (56958000)|VF_DESERIALIZE_VIEWSTATE_END
16:05:35.063 (63809000)|CODE_UNIT_STARTED|[EXTERNAL]|serviceCatalogueCtrl set(subCategory,newone)
16:05:35.063 (63822000)|SYSTEM_MODE_ENTER|true
16:05:35.063 (63838000)|CODE_UNIT_STARTED|[EXTERNAL]|serviceCatalogueCtrl set(subCategory,newone)
16:05:35.064 (64041000)|METHOD_ENTRY|[1]|01p90000003OFvv|serviceCatalogueCtrl.serviceCatalogueCtrl()
16:05:35.064 (64053000)|METHOD_EXIT|[1]|serviceCatalogueCtrl
16:05:35.064 (64071000)|CODE_UNIT_FINISHED|serviceCatalogueCtrl set(subCategory,newone)
16:05:35.064 (64083000)|CODE_UNIT_FINISHED|serviceCatalogueCtrl set(subCategory,newone)
16:05:35.065 (65907000)|CODE_UNIT_STARTED|[EXTERNAL]|01p90000003OFvv|serviceCatalogueCtrl invoke(testJs)
16:05:35.066 (66003000)|METHOD_ENTRY|[7]|01p90000003OFvv|dabur.serviceCatalogueCtrl.__sfdc_subCategory()
16:05:35.066 (66041000)|METHOD_EXIT|[7]|01p90000003OFvv|dabur.serviceCatalogueCtrl.__sfdc_subCategory()
16:05:35.066 (66142000)|SYSTEM_METHOD_ENTRY|[7]|System.debug(ANY)
16:05:35.066 (66177000)|ENTERING_MANAGED_PKG|
16:05:35.066 (66186000)|USER_DEBUG|[7]|DEBUG|Hello subCategory @@newone
16:05:35.066 (66195000)|SYSTEM_METHOD_EXIT|[7]|System.debug(ANY)
16:05:35.066 (66231000)|CODE_UNIT_FINISHED|serviceCatalogueCtrl invoke(testJs)
16:05:35.066 (66263000)|VF_APEX_CALL|j_id3|{!testJs}|PageReference: none
16:05:35.070 (70693000)|VF_SERIALIZE_VIEWSTATE_BEGIN|06690000002wvCT



Sachin10Sachin10

Kwei ChanKwei Chan
Hi, I have a similar issue but I can't fix it even though I do have a name for the param element.
When function profileLinkClick is invoked, I can see the value of billInfoId in Firebug console, but the debug statement on controller side always print 'null' on billHistProfId.
Not sure what I did wrong.  Appreciate your help here.

VF page:
        <script>
        function profileLinkClick(billInfoId) {
            console.debug('In profileLinkClick(): poid=' + billInfoId);
            launchBillProfilePage(billInfoId);
        }

        </script>

        <apex:actionfunction name="launchBillProfilePage" action="{!BillProfPage}">
            <apex:param name="billHistProfId" assignTo="{!billHistProfId}" value="" />
        </apex:actionFunction>

Controller:

  public String billHistProfId {get; set;}  
......
  public PageReference BillProfPage(){     // Creating page reference for billing history profile page      PageReference billProfPage = Page.BillingHistoryProfileList;          // adding URL paarameter (billing info POID) that is coming from billing history page. It is later      // used to identify billing profile uniquely.     system.debug('billHistProfId' + billHistProfId);
.......