1

The apex:param is not passing the contact value to backend. Please correct me where i am going wrong.

 <apex:pageblocktable value="{!lstWrapContactRoles}" var="cr" id="pbt" >
                <apex:column headerValue="Contact">
                    <apex:inputfield value="{!cr.objConRole.Contact__c}" onchange="if(this.value){addfunc();}" id="conId"> <!-- US 410 -->
                      <apex:param name="personID" value="{!cr.objConRole.Contact__c}" assignTo="{!Contactid}" />
                    </apex:inputfield>
                </apex:column>


        <apex:actionfunction name="addfunc" action="{!addNew}" reRender="pbt" oncomplete="codeAddress();checkboxuse();"/>

Apex:

public Id Contactid {get; set;}


  Public vooid addnew(){
system.debug('=='+System.currentPageReference().getParameters().get('personID'));
    system.debug('strContactid'+ApexPages.currentPage().getParameters().get('Contactid')); 

}

Both the debugs are null.

2 Answers 2

2

You have few things wrong here. From documentation:

The <apex:param> component can only be a child of the following components:

  • <apex:actionFunction>
  • <apex:actionSupport>
  • <apex:commandLink>
  • <apex:outputLink>
  • <apex:outputText>
  • <flow:interview>

Whereas, you are using <apex:param> as a child for <apex:inputField>.

Then, you access the values of the param that has been set using the assignTo using getter/setter method, whereas you are trying to access it from a request attribute on the page.


You'll need to review your implementation as what you are trying to achieve, but a typical implementation will look like as:

<apex:actionFunction>    
    <apex:param name="personID" value="{!cr.objConRole.Contact__c}" assignTo="{!ContactId}" />
</apex:actionFunction>

and then in the Apex, you access it as:

public Id ContactId {get; set;}

public void addnew(){
    // just use the variable as declared in the class here        
    system.debug('Contact Id assigned is:' + ContactId); 
}
6
  • Can you help me with the snippet jayant
    – Arvind
    Commented Jan 28, 2019 at 20:36
  • You will need to first change the implementation to correctly use <apex:param> (it cannot be a child of <apex:inputField>, and then access the value in apex by just using ContactId.
    – Jayant Das
    Commented Jan 28, 2019 at 20:38
  • I have updated the answer with the sample snippet. But you will still need to review your implementation as what you are trying to achieve.
    – Jayant Das
    Commented Jan 28, 2019 at 20:43
  • <apex:actionFunction> may not be used within an iterable component. You can use <apex:param> to define parameters for the function and pass iteration-specific values via the parameters. This is the error I am getting
    – Arvind
    Commented Jan 28, 2019 at 20:45
  • Arvind - it's just a sample. As mentioned you will need to go through the details as what you are trying to achieve. I will recommend to first evaluate your use case here, and then go through some VF trailhead and documentation for more details. As the error says, you cannot use <apex:actionFunction> within a loop, so you need to revisit the scenario.
    – Jayant Das
    Commented Jan 28, 2019 at 20:46
1

The apex:param must be a child of the action function.

<apex:inputfield value="{!cr.objConRole.Contact__c}" onchange="if(this.value){addfunc('{!cr.objConRole.Contact__c}');}" id="conId">

...

<apex:actionfunction name="addfunc" action="{!addNew}" reRender="pbt" oncomplete="codeAddress();checkboxuse();">
  <apex:param name="personID" value="" assignTo="{!Contactid}" />
</apex:actionfunction>
9
  • Brain I am still getting null values in my debug. Any solution
    – Arvind
    Commented Jan 28, 2019 at 20:35
  • @Arvind assignTo means you have a variable. Try System.debug(ContactId); instead.
    – sfdcfox
    Commented Jan 28, 2019 at 20:37
  • @Arvind Actually, you're going to have other complications, because you won't get an ID here, but instead a string (e.g. John Doe instead of 003000xxxxxxxxx). This might be the most complicated method of whatever it is you're trying to do.
    – sfdcfox
    Commented Jan 28, 2019 at 20:38
  • Yeah I still get all the values as Null. How can i get the Id in the same method .
    – Arvind
    Commented Jan 28, 2019 at 20:42
  • @Arvind you'll have better luck with apex:actionSupport, instead. You're basically using the wrong tool for the problem you're trying to solve.
    – sfdcfox
    Commented Jan 28, 2019 at 20:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .