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
kardoluskardolus 

Lookup functionality on form field

Hi,

 

I have a VisualForce form field which is used to pass an argument to an Apex method. 

 

I want lookup functionality (to the Campaign object) on this particular field. Users select a campaign, then it gets passed to the Apex method.

 

Is that somehow possible? 

Best Answer chosen by Admin (Salesforce Developers) 
stcforcestcforce

if i understand you correctly, what you want can be accomplished using a select list that is populated in the controller using values found by the controller that reference the campaign. You could have a drop down box of campaigns with values of their ids and then use this in the action method.

All Answers

stcforcestcforce

if i understand you correctly, what you want can be accomplished using a select list that is populated in the controller using values found by the controller that reference the campaign. You could have a drop down box of campaigns with values of their ids and then use this in the action method.

This was selected as the best answer
kardoluskardolus

Thanks man, finally had time to try your idea. Worked!

 

Used something like this in my visualforce page

 

<apex:SelectList id="campaign" size="1" value="{!cam}">
  	<apex:selectOptions value="{!cams}"></apex:selectOptions> 
</apex:SelectList>

 

And something like this in apex controller

 

public String cam {get;set;}
	
public List<selectOption> getCams() {
	List<selectOption> options = new List<selectOption>();
	options.add(new selectOption('', '- None -')); //add the first
	for (Campaign campaigns : [SELECT Id, Name FROM Campaign]) {
		options.add(new selectOption(campaigns.Id,campaigns.Name)); 
	}
	return options; //return the picklist options
}