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
Michael SyproMichael Sypro 

retrieve value of inputField

I think this is a pretty basic question, but it's beating me right now.  I have a list of leads in a pageBlockTable with an inputField for the user to set a new value for the field Follow_up_Date__c.

Visualforce:
<apex:inputField id="txtFDate" value="{!cc.Follow_up_Date__c}" />
<apex:commandLink value="Update" action="{!saveFollowUp}" rerender="leadBlock" >
     <apex:param name="leadId" value="{!cc.Id}" />
</apex:commandLink>
Apex:
public PageReference saveFollowUp(){  
     string leadId=ApexPages.currentPage().getParameters().get('leadId');
     date fDateToUse=?????;

     if (leadId!=null) {
		Lead leadToUse = [select id from lead where id=:leadId limit 1];
	    	leadToUse.Follow_up_Date__c=fDateToUse;
	    	update leadToUse;
     }
     return null;
}

I need help at the question mark line.  How do I get the value from the inputField and save the lead? 

Thanks
Best Answer chosen by Michael Sypro
Michael SyproMichael Sypro
Ah, I figured it out based on your help.
Here's the results:
public List<Lead> l {get;set;} 
    
    public list<Lead> getLeads(){
        l = Database.query('query code');
        return l;
    }

    public PageReference saveFollowUp(){
        string leadId=ApexPages.currentPage().getParameters().get('leadId');
        date f;
        for (Lead leadToLookUp : l){
            if (leadToLookUp.Id==leadId){
                f=leadToLookUp.Follow_up_Date__c;
            }
        }
        Lead leadToUse = [select id from lead where id=:leadId limit 1];
        leadToUse.Follow_up_Date__c=f;
        update leadToUse;
        return null;
    }
The inputField automatically saves to the lead list l.  I just needed to make l a getter/setter and loop through it to get the results.

All Answers

SarfarajSarfaraj
Hi Michael

What is 'cc'? If that is a controller variable and has a public setter, this should work,

date fDateToUse=cc.Follow_up_Date__c;


Michael SyproMichael Sypro
That's the var from my pageBlockTable.  The getLeads function returns all pending leads of the current user.
<apex:pageBlockTable id="customCheckboxPanel" var="cc" value="{!leads}"  >
Is there no way to pull the inputField by its id or save the current value to a param of its own using javascript?  That makes the most sense to me.  Is the controller method the way to go?
SarfarajSarfaraj
Hi Michael

Create a map and populate it while you query lead records. Use it in your save method to get the followup date,

date fDateToUse = leadMap.get(leadId).Follow_up_Date__c;

I have assumed that leads is a variable in your controller and has a public setter. Also I have assumed that your pageblock table is withing one apex:form tag.
Michael SyproMichael Sypro
Ah, I figured it out based on your help.
Here's the results:
public List<Lead> l {get;set;} 
    
    public list<Lead> getLeads(){
        l = Database.query('query code');
        return l;
    }

    public PageReference saveFollowUp(){
        string leadId=ApexPages.currentPage().getParameters().get('leadId');
        date f;
        for (Lead leadToLookUp : l){
            if (leadToLookUp.Id==leadId){
                f=leadToLookUp.Follow_up_Date__c;
            }
        }
        Lead leadToUse = [select id from lead where id=:leadId limit 1];
        leadToUse.Follow_up_Date__c=f;
        update leadToUse;
        return null;
    }
The inputField automatically saves to the lead list l.  I just needed to make l a getter/setter and loop through it to get the results.

This was selected as the best answer