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

Problem with a custom Component



This is what I am trying to do. From a page conatining an Account ID in the  URL (


I want to pass the ID to a component, who then will pass it to a class that queries contacts linked to that ID.


I created these elements:


A page:


<apex:page >
  <c:MyComponent componentValue= ':ApexPages.currentPage().getParameters().get('id')' />  


My page uses a Component, called MyComponent


<apex:component controller="myComponentController">
  <apex:attribute name="componentValue" description="Attribute on the component."
                  type="Id" required="required" assignTo="{!controllerValue}"/>
    <apex:pageBlock title="My Custom Component">
        <code>componentValue</code> is "{!componentValue}"
        <code>controllerValue</code> is "{!}"


This component uses a custom controller called myComponentController


public class myComponentController {
  public Id controllerValue { get; set; }    
  public Contact controllerValueContact;
  public List<Contact> ListContact;

  public myComponentController() {
  public Contact getControllerValueContact() {
    ListContact = [select id, name from Contact where AccountId = :controllerValue];
    controllerValueContact = ListContact.get(0);
    return controllerValueContact;



When I run my page I get this error:


Error: Attribute name "id" associated with an element type "apex:componentReference" must be followed by the ' = ' character. at line 2


Anyone has an idea what am I doing wrong?





Just offhand, I think the problem might be with this line and the parsing of the single quotes:


  <c:MyComponent componentValue= ':ApexPages.currentPage().getParameters().get('id')' />   


It thinks you're generating:

<c:MyComponent componentValue= ':ApexPages.currentPage().getParameters().get('         id    and at this point it's expecting the "=" sign because now you're assigning the Id attribute.




Perhaps what you want is escaped single quotes so they aren't ending your string literal


  <c:MyComponent componentValue= ':ApexPages.currentPage().getParameters().get(\'id\')' />   


Don't you hate trivial stuff like this... aren't computers supposed to know what we want by now!  :-)


Best, Steve.