You need to sign in to do that
Don't have an account?
Melissa Howard
Visualforce page won't recognize APEX extended controller
I have the following APEX class:
public class ContactExtendedController {
public List<Contact> getContacts() {
return [SELECT Id, 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];
}
}
And this opening to my VF page errors:
<apex:page standardController="Contact" extensions="ContactExtendedController">
with error: Error: Unknown constructor 'ContactExtendedController.ContactExtendedController(ApexPages.StandardController controller)'
This seems so simple a thing. I can't understand why the "extensions" clause isn't working.
Thanks much,
Evan
public ContactExtendedController(ApexPages.StandardController controller) {
}
1. create some properties eg. public [data-type] [property-name]{get; set;}
2. bind that property with input field e.g <apex:inputfield value={![property-name]}"/>
once we are done with these step. input field is ready to recieve the value back.
Now you can fire the select query and assign respective field to property and it will populate the field for you. hope this resolve the query.
Error: Could not resolve the entity from <apex:inputField> value binding '{!lastname}'. <apex:inputField> can only be used with SObjects, or objects that are Visualforce field component resolvable.
public with sharing class ContactExtendedController2 { public Contact contactSetting{get;set;} public String firstname {get; set;} public String lastname {get; set;} public String email {get; set;} public ContactExtendedController2(ApexPages.StandardController Contact) { contactSetting=new Contact(); contactSetting = [SELECT Id, Name FROM Contact WHERE FirstName = :firstname AND LastName = :lastname AND (Email = :email OR npe01__WorkEmail__c = : email)]; } } 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"> <!-- <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="{!contactSetting.Name}" /> <apex:inputfield value="{!lastname}"/> <apex:inputfield value="{!email}"/> <apex:variable var="firstName" value="{!Contact.FirstName}" /> <apex:variable var="lastName" value="{!Contact.LastName}" /> <apex:outputLabel value="Lookup Contact" for="ContactLookup"/> <apex:inputField id="RequestedBy" value="{!contactSetting.Name}" /> <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>
Error is "Error: Compile Error: Non-void method might not return a value or might have statement after a return statement. at line 15 column 9"
public with sharing class ContactExtendedController2 {
public Contact contactSetting{get;set;}
public String firstname {get; set;}
public String lastname {get; set;}
public String email {get; set;}
public ContactExtendedController2(ApexPages.StandardController Contact) {
contactSetting=new Contact();
contactSetting = [SELECT Id, Name FROM Contact
WHERE FirstName = :firstname AND LastName = :lastname AND
(Email = :email OR npe01__WorkEmail__c = : email)];
}
public pagereference save(){
update contactSetting;
}
}
Also, why do we need the last method? This in conjunction with the VF perform a lookup on Contact based on the inputted Email, FirstName and LastName. The updated contact, after all form entries, is saved on the VF page by <apex:commandButton action="{!save}" value="Update"/>.
first of all i do appologize for the mistake in the code. Please add return null line #11. Since this method is returning pagereference.
we need last method in order to push the updated data back to data store.
and yes, change the SOQL query , add all fields which are required in VF for contact objects. if you don't include, it won't get the data to display. if you are updating the existing data.
hope this resolve the query.
Here is the current APEX. I don't understand what you mean about returning NULL on line 11.
public with sharing class ContactExtendedController2 {
public Contact contactSetting{get;set;}
public String firstname {get; set;}
public String lastname {get; set;}
public String email {get; set;}
public ContactExtendedController2(ApexPages.StandardController Contact) {
contactSetting=new Contact();
contactSetting = [SELECT Id, Name FROM Contact
WHERE FirstName = :firstname AND LastName = :lastname AND
(Email = :email OR npe01__WorkEmail__c = : email)];
}
public pagereference save(){
update contactSetting;
}
}
Here is the VF. Note the <apex:variable> statements. Those variables are needed by the APEX to do the lookup. Right? They get set after the user inputs Contact.Firstname, .Lastname, and .Email on the form.
2. one thing which i have noticed. we dont have any Contact object in apex code. change it to contactSetting.
Here's the APEX code:
public with sharing class ContactExtendedController2 {
public Contact contactSetting{get;set;}
public String firstname {get; set;}
public String lastname {get; set;}
public String email {get; set;}
public ContactExtendedController2(ApexPages.StandardController Contact) {
contactSetting=new contactSetting();
contactSetting = [SELECT Id, FirstName, LastName, Email, HomePhone FROM Contact
WHERE FirstName = :firstname AND LastName = :lastname AND
(Email = :email OR npe01__WorkEmail__c = : email)];
}
if (contactSetting == null){
ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.info,constantClass.'Hello'));
}
public pagereference save(){
update contactSetting;
return null;
}
}
Thank you so much SMRPRNBRTH (https://developer.salesforce.com/forums/ForumsProfile?communityId=09aF00000004HMG&userId=005F00000042u2G&showHeader=false" id="ext-gen44), for helping me to finish my first small VF coupled with APEX feature!
It would be great if you mark the answer as best answer. It would be a good recognization from your side.
Hey, would you mind looking at my last post? I have one last syntax error and I think I will be done.
Thanks!!
Evan
Thank you for hitting like for the post. However the person who initiate the post can only choose the "Best Answer". I'll have a look to your post. It would be really great if you can post me a link to your problem.