0

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 {
   insert(weblead);
   }
   catch(System.DMLException e) {
       ApexPages.addMessages(e);
       return null;
   }
   PageReference p = Page.ThankYou;
   p.setRedirect(true);
   return p;
 }

And the highlights of the VF page:

<apex:page standardController="Lead"
       extensions="myWeb2LeadExtension"
       title="Register for Digital Accelerator" showHeader="false"
       standardStylesheets="true">

<apex:composition template="{!$Site.Template}">
<apex:define name="body">
<apex:form >
<apex:messages id="error"
               styleClass="errorMsg"
               layout="table"
               style="margin-top:1em;"/>
  <apex:pageBlock title="" mode="edit">
    <apex:pageBlockButtons >
       <apex:commandButton value="Submit"
                           action="{!saveLead}"/>
    </apex:pageBlockButtons>
    <apex:pageBlockSection title="Register for Digital Accelerator"
                           collapsible="false"
                           columns="1">
    <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"/>

    </div>
    <apex:inputHidden id="{!Lead.Referred_By__c}"
                      value="{!$CurrentPage.parameters.Referred"/>

    </apex:pageBlockSection>
 </apex:pageBlock>

1 Answer 1

2

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.

4
  • 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 .