5

Lets assume I have a Page code:

<apex:pageBlockTable value="{!allContacts}" var="c" >
            <apex:column value="{!c.id}" headervalue="ID"/>
            <apex:column value="{!c.FirstName}" headervalue="First Name"/>
            <apex:column value="{!c.LastName}" headervalue="Last Name"/>
            <apex:column value="{!c.Title}" headervalue="Title"/>
            <apex:column value="{!c.Company}" headervalue="Company"/>
            <apex:column>
                <apex:commandButton action="{!addToRecruits}" value="Recruit">
                    <apex:param assignTo="{!leadID}" name="leadID" value="{!c.id}"/>
                </apex:commandButton>
            </apex:column>
</apex:pageBlockTable>

And relevant controller :

    public String leadID { get; set; }

    public PageReference addToRecruits() {
        System.debug('LeadID is: ' + leadID);
        List<Lead> potentialCandidate = [SELECT id, FirstName, lastName, Title, Company FROM Lead WHERE id = :leadID];   
        delete potentialCandidate;

        return null;
    }

It seems that I can NOT pass leadID to addToRecruits() method. Do you have any idea why is so?

UPDATE:

I could manage to solve it. Instead of querying using SOQL, I approached with this style:

public String leadID { get; set; }
public PageReference addToRecruits() {

    Lead candidate=new Lead(id=leadID);
    ....
}
2
  • I've had similar code working ok in the past. What result do you see in the log? Jan 2, 2013 at 17:30
  • @RobWoodward I solved it . I will update my question to clarify it ..
    – Soask
    Jan 2, 2013 at 20:33

2 Answers 2

9

There's a long outstanding defect with passing parameters from an apex:commandButton. A hack to get around the defect is to set the rerender attribute on the apex:commandButton element. See Bob Buzzard's blog: http://bobbuzzard.blogspot.com/2011/07/passing-parameters-to-apex-method-from.html

2
  • Another description of the issue from Salesforce: help.salesforce.com/apex/… Jan 2, 2013 at 20:47
  • Thanks. That's actually what I did to solve the situation. I'm new to this platform, and I didn't know that this is a big defect..
    – Soask
    Jan 2, 2013 at 21:43
3

It's a "known bug" by the dev community but it never made to the list...

Jeff Douglas has written this up together with viable workarounds in March 2010: http://blog.jeffdouglas.com/2010/03/04/passing-parameters-with-a-commandbutton/ (the post and comments also contain few useful links to SF message boards).

1

You must log in to answer this question.

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