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
Johannes PohlmannJohannes Pohlmann 

Use lookup value as parameter

Hi all,
I'm fairly new to Salesforce, especially Visualforce, so this might be a rather simple problem but I can't figure it out. I'm trying to create a VF Page with a lookup field for users to select a Course__c and then pass the selected Course as a parameter to an apex method for further processing. The lookup field itself is not a problem, neither is passing a hardcoded value (here the three question marks as a string) but how can I dynamically assign the selected value from the lookup to my parameter?
Thank you

VF-Page:
<apex:page controller="mycontroller">  
    <apex:form >
        <apex:inputField label="Find a Course" id="theLookup" value="{!Firstname.Course__c}"/>
        <apex:commandButton value="GO" action="{!processButtonClick}" rerender="hiddenBlock">
            <apex:param name="myCourse"
                value="???"
                assignTo="{!myCourse}"/>
        </apex:commandButton>
        <apex:pageBlock id="hiddenBlock" rendered="false"></apex:pageBlock>
    </apex:form>
</apex:page>

Controller:
public with sharing class mycontroller {
    public Course__c myCourse {
        get;
        set {
            myCourse = value;
        }
    }
    public Course_Group__c getFirstname(){
        return new Course_Group__c();
    }
    public PageReference processButtonClick() {
        System.debug('nickName: '+myCourse);
        // here I'd call my apex method with the selected Course as parameter
        return null;
    }
}

Matthew CokeMatthew Coke
you shouldn't need "  myCourse = value;", the assignTo property in the VF page should do it automatically
Johannes PohlmannJohannes Pohlmann

You're right Matthew. I read somewhere that I should put it in there but apparently it's not necessary, thank you.
However this doesn't help with my actual problem.