You need to sign in to do that
Don't have an account?
Evan 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
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
Try this instead: 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.
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
Thanks again.
<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>
https://developer.salesforce.com/forums/ForumsMain?id=906F0000000AcplIAC