Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Prefilling fields is easy on standard edit pages via an URL parameter, like .../a0B/e?Name=MyNameValue Doing this on a visualforce page does not work without custom controllers, or is there a way?

Problem description:

URL .../apex/MyVFPage?Name=MyNameValue

<apex:inputField value="{!MyCustomObject__c.Name}" id="Name">

Name in URL does not populate field with id="Name".

share|improve this question
If you actually inspect the element on the page of your VF page, that input field doesn't have an id of 'Name'. It has some Id similar to "j_ido:jid1_:name". This is how the VF is converted to html. Is there a reason you don't want to use a standardController and add an extension? – Chris Duncombe Feb 20 '14 at 14:51
up vote 6 down vote accepted

Sorry I misunderstood you.

here is a the right solution for your problem

<apex:page standardController="Lead">
        <apex:inputtext  id="jsName"/>
            var jsName = "{!$Component.jsName}";



         document.getElementById(jsName).value = "{!$CurrentPage.parameters.Name}";

And don't forget that you can't use the inputField, because it needs to be bond to an existing sObject Field

share|improve this answer
Make sure you use the JSENCODE around your parameters. Otherwise you are opening security loopholes. – dphil Feb 20 '14 at 15:43
Thank you very much Melmoussaoui. It works like a charm. – snstulemeijer Feb 21 '14 at 8:24

You will need at least a standardController specified on your visualforce page as apex:inputfield needs to bind to a SObject. It can be the standard controller for you custom object. As for prefilling the form, you will need to use some JavaScript.

<apex:page standardController="MyCustomObject__c" id="mainPage">
    <apex:form id="mainForm">
        <apex:inputField value="{!MyCustomObject__c.Type__c}" id="typeField"/>

        window.onload = function() {
            document.getElementById('mainPage:mainForm:typeField').value = "{!$CurrentPage.parameters.type}";
share|improve this answer

You can get the parameters using an extension:

public class MyExtension {

    private MyCustomObject__c record;
    public MyExtension(ApexPages.StandardController controller) {
        record = (MyCustomObject__c) controller.getRecord();
        record.Name = ApexPages.currentPage().getParameters().get('Name');
share|improve this answer

Your Answer


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.