+ Start a Discussion
Evan BurnsEvan Burns 

Simple APEX won't compile

I have this APEX code for a Contact extended controller. All it does is put a Contact lookup on the VF page, and display the 10 most recent contacts in that lookup.

I have stared at it and stared at it, and I just can't find the error. The error, on line 5, is: expecting a semi-colon, found '('

public class FoodbankContactExtendedController {

    public FoodbankContactExtendedController(ApexPages.StandardController Contact) {
        // Return a list of the ten most recently modified contacts
        public List<Contact> getContacts() {
        return [SELECT Id, Name, Contact.Name, Phone, Email
            FROM Contact
            ORDER BY LastModifiedDate DESC LIMIT 10];
    }

    // Get the 'id' query parameter from the URL of the page.
    // If it's not specified, return an empty contact.
    // Otherwise, issue a SOQL query to return the contact from the
    // database
   
    public Contact getContact() {
    Id id = System.currentPageReference().getParameters().get('id');
    return id == null ? new Contact() : [SELECT Id, Name
        FROM Contact
        WHERE Id = :id];
    }
}

Does anybody have any idea why this simple code won't compile?

Thanks,

Evan
claperclaper
Hi Evan, 

Try this instead:
public class FoodbankContactExtendedController {

   public List<Contact> getContacts() {
        return [SELECT Id, Name, Contact.Name, Phone, Email
            FROM Contact
            ORDER BY LastModifiedDate DESC LIMIT 10];

    public FoodbankContactExtendedController(ApexPages.StandardController Contact) {
        // Return a list of the ten most recently modified contacts
        
    }

    // Get the 'id' query parameter from the URL of the page.
    // If it's not specified, return an empty contact.
    // Otherwise, issue a SOQL query to return the contact from the
    // database
   
    public Contact getContact() {
    Id id = System.currentPageReference().getParameters().get('id');
    return id == null ? new Contact() : [SELECT Id, Name
        FROM Contact
        WHERE Id = :id];
    }
}
if you are using {!Contacts} or {!Contact} merge field in your visualforce page, you do not need to call the function in the controller, neither write the function inside the controller.
Evan BurnsEvan Burns
Hi Claper,

Thank you for the code. I have a question though. Yes I will use contact merge fields on the VF page. So, why don't I need this lookup field like this in my controller? Maybe that's not what you're saying.

Evan
Evan BurnsEvan Burns
Your code compiles fine. So aren't I good to use it in the inputField on the VF page for the lookup?

Thanks again.
claperclaper
Can you post you vf page as well? I'm not sure what you are trying to accomplish
Evan BurnsEvan Burns
The VF is fine except for it's trying to reference the extended controller on line 8. Here it is:

<apex:page standardController="Contact" extensions="FoodbankContactExtendedController">

    <apex:form >
        <apex:pageBlock title="Foodbank of Santa Barbara County Volunteer Information">
            <apex:pageBlockSection columns="1">
                <!-- <b>Input Date  :</b><apex:inputfield value="TODAY"/> This gives error, even if value="7/21/2014"
                <apex:outputLabel value="Lookup Contact" for="ContactLookup"/> -->
                <apex:inputField id="RequestedBy" value="{!FoodbankContactExtendedController()}"/>
                <apex:inputField value="{!Contact.FirstName}"/>
                <apex:inputField value="{!Contact.LastName}"/>
                <apex:inputField value="{!Contact.Email}"/>
                <apex:inputField value="{!Contact.Broad_Area_s_You_Want_to_Help_with__c}"/>
                <apex:inputField value="{!Contact.Other_Broad_Area__c}"/>
                <apex:inputField value="{!Contact.Ways_You_Would_Like_to_Help__c}"/>                               
                <apex:inputField value="{!Contact.Other_Way_s_You_Would_Help__c}"/>                                               
                <apex:inputField value="{!Contact.Volunteer_Job_Categories__c}"/>                                               
                <apex:inputField value="{!Contact.GW_Volunteers__Volunteer_Availability__c}"/>                
                <apex:inputField value="{!Contact.Your_Location__c}"/>                                               
                <apex:inputField value="{!Contact.Language_Fluency__c}"/>                                               
                <apex:inputField value="{!Contact.Administrative_Office_Skills__c}"/> 
                <apex:inputField value="{!Contact.IT_Skills__c}"/>
                <apex:inputField value="{!Contact.Marketing_Design_Skills__c}"/>                
                <apex:inputField value="{!Contact.Events_Skills_Interests__c}"/>               
                <apex:inputField value="{!Contact.Fundraising_Community_Outreach_Skills__c}"/>               
                <apex:inputField value="{!Contact.Writing_Editing_Skills__c}"/>               
                <apex:inputField value={!Contact.Leadership_Consultant_Skills__c}"/>                                                                                                                                                                                                          
                <apex:inputField value="{!Contact.Warehouse_Harvesting_Food_Skills__c}"/>               
                <apex:inputField value="{!Contact.Educator_Teaching_Skills__c}"/>               
                <apex:inputField value="{!Contact.Other_Skills__c}"/>               
                <apex:inputField value="{!Contact.Other_Skill__c}"/>               
                <apex:commandButton action="{!save}" value="Update"/>

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


    <apex:detail relatedList="false"/>
</apex:page>
claperclaper
what are you trying to do with " " ?? Clara PérezSalesforce Developer
Sameer PrasonnSameer Prasonn
public with sharing class ContactExtendedController2 {
    public Contact contactSetting{get;set;}
    public ContactExtendedController2(ApexPages.StandardController Contact) {
        contactSetting=new Contact();
        contactSetting = [SELECT Id, Name,FirstName,LastName,Broad_Area_s_You_Want_to_Help_with__c,Other_Broad_Area__c , Ways_You_Would_Like_to_Help__c , Other_Way_s_You_Would_Help__c, Volunteer_Job_Categories__c, GW_Volunteers__Volunteer_Availability__c ,Your_Location__c,Language_Fluency__c,Administrative_Office_Skills__c,IT_Skills__c,Marketing_Design_Skills__c,Events_Skills_Interests__c,Fundraising_Community_Outreach_Skills__c,Writing_Editing_Skills__c,Leadership_Consultant_Skills__c,Warehouse_Harvesting_Food_Skills__c,Educator_Teaching_Skills__c,Other_Skills__c  FROM Contact
           WHERE FirstName = :firstname AND LastName = :lastname AND
                (Email = :email OR npe01__WorkEmail__c = : email)];
 
    }
    public pagereference save(){
        update contactSetting;
        return null;
    }

}

  
Here is the VF:
<apex:page standardController="Contact" extensions="ContactExtendedController2">
 
    <apex:form >

        <apex:pageBlock title="Foodbank of Santa Barbara County Volunteer Information">
            <apex:pageBlockSection columns="1">
                <apex:outputLabel value="Lookup Contact" for="ContactLookup"/>
                <apex:inputText id="RequestedBy" value="{!contactSetting.Name}" />
                <apex:inputText value="{!Contact.FirstName}"/>
                <apex:inputText value="{!Contact.LastName}"/>            
                <apex:outputLabel value="Lookup Contact" for="ContactLookup"/>
                <apex:inputText id="RequestedBy" value="{!contactSetting.Name}" />
                <apex:inputText value="{!Contact.Broad_Area_s_You_Want_to_Help_with__c}"/>
                <apex:inputText value="{!Contact.Other_Broad_Area__c}"/>
                <apex:inputText value="{!Contact.Ways_You_Would_Like_to_Help__c}"/>                          
                <apex:inputText value="{!Contact.Other_Way_s_You_Would_Help__c}"/>                          
                <apex:inputText value="{!Contact.Volunteer_Job_Categories__c}"/>                                    
                <apex:inputText value="{!Contact.GW_Volunteers__Volunteer_Availability__c}"/>              
                <apex:inputText value="{!Contact.Your_Location__c}"/>                                              
                <apex:inputText value="{!Contact.Language_Fluency__c}"/>                                              
                <apex:inputText value="{!Contact.Administrative_Office_Skills__c}"/>
                <apex:inputText value="{!Contact.IT_Skills__c}"/>
                <apex:inputText value="{!Contact.Marketing_Design_Skills__c}"/>               
                <apex:inputText value="{!Contact.Events_Skills_Interests__c}"/>              
                <apex:inputText value="{!Contact.Fundraising_Community_Outreach_Skills__c}"/>          
                <apex:inputText value="{!Contact.Writing_Editing_Skills__c}"/>              
                <apex:inputText value="{!Contact.Leadership_Consultant_Skills__c}"/>                               
                <apex:inputText value="{!Contact.Warehouse_Harvesting_Food_Skills__c}"/>              
                <apex:inputText value="{!Contact.Educator_Teaching_Skills__c}"/>              
                <apex:inputText value="{!Contact.Other_Skills__c}"/>              
                <apex:inputText value="{!Contact.Other_Skill__c}"/>              
                <apex:commandButton action="{!save}" value="Update"/>
            </apex:pageBlockSection>
        </apex:pageBlock>

    </apex:form>
    <apex:detail relatedList="false"/>
</apex:page>
Hope this resolve the query you are asking for!!! happy coding :D
Sameer PrasonnSameer Prasonn
for further mode details you can refer to this post
https://developer.salesforce.com/forums/ForumsMain?id=906F0000000AcplIAC