You need to sign in to do that
Don't have an account?
Error: Unknown property with custom object
Let me start off by saying I've searched high and low for an answer on the boards and the web and I still came up empty handed.
I'm having difficulty creating an Apex controller. My intention is to use the controller so new records can be submitted on a publicly available force.com site by Guest Usrers, essentially a web to to lead but to my custom object Agent_Portal__c.
I'm receiving two errors when I implement the controller on my VF page. They are Error: Unknown Property 'AgentPortalCreateController.Agent_Portal__c' and then it gives me two links to Create Apex property 'AgentPortalCreateController.Agent_Portal__c' and Create Apex method 'AgentPortalCreateController.getAgent_Portal__c'. I click on the links hoping that it will fix the problem but then I get two error Invalid identifier: getAgent_Portal__c and Invalid identifier:Agent_Portal__c when I click on both links.
Any insight how I can fix this?
Visualforce Code:
<apex:page Controller="AgentPortalCreateController" showHeader="false">
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton action="{!save}" value="Submit"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Referral Information" columns="1">
<apex:pageBlockSection >
<apex:inputField value="{!Agent_Portal__c.Insured_s_Name__c}"/>
</apex:pageBlockSection>
<apex:pageBlockSection >
<apex:inputField value="{!Agent_Portal__c.Insured_s_Phone__c}"/>
</apex:pageBlockSection>
<apex:pageBlockSection columns="1" >
<apex:inputField value="{!Agent_Portal__c.Agency_Name__c}" required="true"/>
</apex:pageblocksection>
<apex:pageBlockSection >
<apex:inputField value="{!Agent_Portal__c.Agency_Contact__c}"/>
</apex:pageBlockSection>
<apex:pageBlockSection >
<apex:inputField value="{!Agent_Portal__c.Insurance_Company__c}"/>
</apex:pageBlockSection>
<apex:pageBlockSection >
<apex:inputField value="{!Agent_Portal__c.Rental_Coverage__c}"/>
</apex:pageBlockSection>
<apex:pageBlockSection >
<apex:inputField value="{!Agent_Portal__c.Additional_Comments__c}"/>
</apex:pageBlockSection>
<apex:pageBlockSection >
<apex:inputField value="{!Agent_Portal__c.Location__c}"/>
</apex:pageBlockSection>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller:
public with sharing class AgentPortalCreateController {
// the referral record you are adding values to
public Agent_Portal__c referral {
get {
if (referral == null)
referral = new Agent_Portal__c();
return referral;
}
set;
}
public AgentPortalCreateController() {
// blank constructor
}
// save button is clicked
public PageReference save() {
try {
insert referral; // inserts the new record into the database
} catch (DMLException e) {
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error creating new contact.'));
return null;
}
// if successfully inserted new contact, then displays the thank you page.
return Page.Contact_Create_Thankyou;
}
}
Here's a short controller snippet that should give you an example of how it's done. Notice that Agent_Portal__c is a custom object and there is a controller member called ap. You need to reference the member not the class, just like you do in other Apex coding:
All Answers
It looks like your controller doesn't have a member called Agent_Portal__c. It has a couple of methods, but your VF page is looking for a member.
add to your controller
public Agent_Portal__c ap {get; set;}
then have your controller methods set ap to the object you want to reference in your VF page.
@JeffM - Thanks, I tried what you suggested and I'm still getting the same problem.
In your controller, you'll need to set the object to a record.
for example:
class controller() {
public Agent_Portal__c ap {get;set;}
controller() {
ap = new Agent_Portal__c();
ap.Name = 'Tester';
}
}
Now you'll be able to reference ap in your VF page.
like this:
{!ap.Name}
Jeff,
I appreciate the response. As you can tell I'm a noob at Apex, but I'm learning (i think). To make sure I'm on the same wave length with you, I currently have the controller set to the object (Agent_Portal__c). So you're stating that I need to set the object to a record such as Insured_s_Name__c which is a custom field in the object. Right?
Thanks for the help thus far!
Here's a short controller snippet that should give you an example of how it's done. Notice that Agent_Portal__c is a custom object and there is a controller member called ap. You need to reference the member not the class, just like you do in other Apex coding: