I'm trying to add a lookup field inside a pageblocktable iteration component.

I have the following code:


<apex:column headerValue="Contact" headerClass="ct" >

    <apex:inputField value="{!c.Contactid}" id="inputField"/>

    <apex:inputHidden id="hdnField" value="{!contactId}" />

    <apex:commandLink value="+" styleClass="btn" style="color:red;font-size:15px;" onclick="setVar();" action="{!updateCase}" >

        <apex:param name="caseId"
                    assignTo="{!caseId}" />

        <apex:param name="contactId"
                    assignTo="{!contactId}" />                            




function setVar(){
    j$ = jQuery.noConflict();
    var newId = j$('[id$=inputField_lkid]').attr( "value" )

Apex Controller:

public Case currentCase{get;set;}
public Id caseId {get;set;}

public void updateCase() {

    this.currentCase = [SELECT Id FROM Case WHERE Id = :caseId];
    currentCase.ContactId = this.contactId;
    update currentCase;


However when I click the button the new contact ID is not being passed to the controller, instead it's a blank value(case Id works fine). Does anybody have an idea where I'm going wrong?

1 Answer 1


Your controller method is declared using the keyword void. That means it doesn't return anything. What it does do is initiate a query based on the a selected case using the caseId. From there it updates the currentCase using a supplied ContactID.

Your JQuery function is getting the contactId and setting it for you. What I don't see is where or how the ContactId is being passed into the updateCase() method.

You'll notice that the method references this.currentCase, but I see no mention of ContactId and it's not a parameter that's specified in the method. Unless you have a getter for the contactId that functions with that same action method, you may need to add an additional method that supports passing the value along the lines of what's below:

public void updateCase(Id ContactId) {

    this.currentCase = [SELECT Id FROM Case WHERE Id = :caseId];
    currentCase.ContactId = this.contactId;
    update currentCase;


With the above, it doesn't appear that you're passing the new contactId into the method and/or you may not have the caseId being passed along with it too as it needs both sent at the same time.

  • Thanks crmprogdev, I've updated my port. I forgot I do have properties for 'caseId' and 'contactId' defined. My '<apex:param>' is nested inside a commandLink element so it passes both 'contactId' and 'caseId' along. I pull back the 'currentCase' (and store it in this.currentCase) using the caseId. When I have System.Debug statements at the start of my updateCase method, the caseId is displayed but the contactId isn't. I think it's not being passed in properly.'code'(hello)
    – user24634
    Oct 23, 2015 at 17:59
  • 1
    What does your JS console show for values Onclick? Are the variables being updated in the jQuery? I'd also suggest you add debug statements to see what's happening on the controller side to get the values there.
    – crmprogdev
    Oct 23, 2015 at 20:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy