I'm trying to fill a hidden custom field through a parameter provided via the URL in a Visualforce page on a Force.com site that creates leads. I'm getting the following error:

"Error: Literal value is required for attribute id in apex:inputHidden in NomineeRegistration at line 38 column 99."

Here's my Apex:

public class myWeb2LeadExtension {

private final Lead weblead;

public myWeb2LeadExtension(ApexPages.StandardController
                            stdController) {
   weblead = (Lead)stdController.getRecord();

 public PageReference saveLead() {
   try {
   catch(System.DMLException e) {
       return null;
   PageReference p = Page.ThankYou;
   return p;

And the highlights of the VF page:

<apex:page standardController="Lead"
       title="Register for Digital Accelerator" showHeader="false"

<apex:composition template="{!$Site.Template}">
<apex:define name="body">
<apex:form >
<apex:messages id="error"
  <apex:pageBlock title="" mode="edit">
    <apex:pageBlockButtons >
       <apex:commandButton value="Submit"
    <apex:pageBlockSection title="Register for Digital Accelerator"
    <div class = "requiredInput">
    <div class = "requiredBlock"></div>
     <apex:inputField value="{!Lead.FirstName}" required="true"/>
     <apex:inputField value="{!Lead.LastName}" required="true"/>
     <apex:inputField value="{!Lead.Nickname__c}" required="false"/>
     <apex:inputField value="{!Lead.Title}" required="true"/>
     <apex:inputField value="{!Lead.Email}" required="true"/>
     <apex:inputField value="{!Lead.Company}" required="true"/>
     <apex:inputField value="{!Lead.Phone}" required="true"/>
     <apex:inputField value="{!Lead.Mailing_Address__c}" required="true"/>

    <apex:inputHidden id="{!Lead.Referred_By__c}"


1 Answer 1


You can't dynamically bind html Ids in Visualforce. You should generate a Web2Lead form in Salesforce setup with this field on it, and grab the Id from there.

  • thank you. If I use a static ID would that work? For example, would ` value="Google.com" ` work?
    – W Edwards
    Jun 13, 2016 at 18:23
  • 2
    The Id in this case refers to the field Id so that the Web2Lead engine can map it properly. The value can be dynamic. Jun 13, 2016 at 18:24
  • Daniel, based on this site, Could I recreate this <input type="hidden" name="Campaign_ID" value="70120000000U4eJ" /> ? I don't think we need Ids do we?
    – W Edwards
    Jun 13, 2016 at 18:30
  • 1
    @WEdwards I think in that SFDC Help link, SFDC is relying on some predefined OOB fields for campaignID and member status. For custom fields, you have to use the field ID obtained via inspection using Browser developer tools like firebug.
    – cropredy
    Jun 14, 2016 at 1:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .