Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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);
    ....
}
share|improve this question
    
I've had similar code working ok in the past. What result do you see in the log? –  Rob Woodward Jan 2 '13 at 17:30
    
@RobWoodward I solved it . I will update my question to clarify it .. –  Soask Jan 2 '13 at 20:33

2 Answers 2

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

share|improve this answer
    
Another description of the issue from Salesforce: help.salesforce.com/apex/… –  James Loghry Jan 2 '13 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 '13 at 21:43

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).

share|improve this answer
    
Pramod, congratulations on your copy-paste skills... salesforce.stackexchange.com/a/4950/799 –  eyescream Oct 13 at 10:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.