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
Karina ChangKarina Chang 

How can I store a parameter into a custom lead field?

I have created a form in Visualforce page, which will create a lead in SFDC. So far, it is looking and working as expected.
However, I would like to pass some values without making it visible on the Visualforce page.

For example, the URL ends in ".......?param1=ClassName&param2=ABC"
I have an extension that gets the values of param1 and param2.

On the visualforce page - I have:  <apex:outputText value="{!Param2}" style="width:225px"/> 
and other fields that are getting entered manually: <apex:inputText value="{!lead.Company}" style="width:225px"/>
 

How can I store the {!Param2} value into a custom lead field (Training_Location_and_Date__c)?
When the lead is created, the custom field is empty.



 
Best Answer chosen by Karina Chang
Apoorv Saxena 4Apoorv Saxena 4
Hi Karina,

you can get the URL parameter using following code:

For eg: If you need to get value of param2, the you could do something like this:
Declare a public variable like :

public String myParam2;

now in your constructor you can get the parameter by using following syntax:

myParam2 =  ApexPages.currentPage().getParameters().get('param2');

now you have the value passed in param2 URL parameter in you String variable name 'myParam2'.

Now in the method, in which you are inserting lead just set this value in the field you want like :

Let say your method name is createLead, so you could do something like :
 
public pageReference createLead(){
	Lead ld=new Lead();
	ld.lastname = 'Any name';
	ld.Training_Location_and_Date__c = myParam2;
	// Set other fields;
	insert ld;
	return new PageReference('/'+ld.id)
}

Please let me know how this works for you, mark this as Solved if this helps you so that others can view it as a proper solution.

Thanks,
​Apoorv
 

All Answers

Apoorv Saxena 4Apoorv Saxena 4
Hi Karina,

you can get the URL parameter using following code:

For eg: If you need to get value of param2, the you could do something like this:
Declare a public variable like :

public String myParam2;

now in your constructor you can get the parameter by using following syntax:

myParam2 =  ApexPages.currentPage().getParameters().get('param2');

now you have the value passed in param2 URL parameter in you String variable name 'myParam2'.

Now in the method, in which you are inserting lead just set this value in the field you want like :

Let say your method name is createLead, so you could do something like :
 
public pageReference createLead(){
	Lead ld=new Lead();
	ld.lastname = 'Any name';
	ld.Training_Location_and_Date__c = myParam2;
	// Set other fields;
	insert ld;
	return new PageReference('/'+ld.id)
}

Please let me know how this works for you, mark this as Solved if this helps you so that others can view it as a proper solution.

Thanks,
​Apoorv
 
This was selected as the best answer
Karina ChangKarina Chang
If I understand correctly, this works to set the 'param' value into the Location and Date field.
But, what about the LastName... I am allowing the user to enter the Last Name in the visualforce page using <apex:inputField>.
How can I reference that field in the createLead method, correct?
Apoorv Saxena 4Apoorv Saxena 4
Hi Karina,

If you're using <apex:inputField value="{!lead.lastname}" /> on VF page, you can use it in your controller method like:
 
public pageReference createLead(){
	Lead ld=new Lead();
	ld.lastname = lead.lastname;
	ld.Training_Location_and_Date__c = myParam2;
	// Set other fields;
	insert ld;
	return new PageReference('/'+ld.id)
}

Hope this helps!
Karina ChangKarina Chang
Great! it worked.... Thanks!