You need to sign in to do that
Don't have an account?
CustomController error; Undefined Constructor
Hello, This custom controller is attempting to read data from the User and Contact object from a Case record but the VF fails to compile with 'Unknown constructior CPcontroller.CPcontroller().'
I think the main issue is I'm not able to get the Case Id correctly in the controller when I try to use the Apex.Pages.StandardController.
How can I retrieve the Case Id of my current record using this custom controller.
VF and Controller code is as follows:
public class CPcontroller {
private final Case ca;
public CPcontroller(ApexPages.StandardController controller) {
this.ca = (Case)controller.getRecord();
cid = ca.id;
conid = ca.ContactId;
system.debug('cid is :' +cid);
}
public User getUser() {
return [select id,Name,ContactId,TimeZoneSidKey,Account_Sharing__c, Title, CompanyName,Phone,Extension,Fax,MobilePhone,
Email,Street,City,State,Country,PostalCode,CurrencyIsoCode from User where ContactId =
:conid];
}
public Contact getContact() {
return [select id, Name,Email,Phone,Fax,MailingStreet,MailingCity,MailingState,MailingPostalCode,MailingCountry,Title,
ContactAccountName__c from Contact where Id = :conid];
}
private Id cid { // Get the Case Id
get {
if(ApexPages.currentPage().getparameters().get('cid') != null) {
cid = ApexPages.currentPage().getparameters().get('cid');
}
return cid;
}
set {
if(value != null) cid = value;
}
}
private Id conid { // Get the Contact Id
get {
if(ApexPages.currentPage().getparameters().get('conid') != null) {
conid = ApexPages.currentPage().getparameters().get('conid');
}
return cid;
}
set {
if(value != null) conid = value;
}
}
}
<apex:page controller="CPcontroller" tabStyle="User"> <apex:form > <apex:pageBlock > <apex:pageBlockSection title="User Info"> <apex:outputField value="{!User.Name}"/> <apex:outputField value="{!User.Title}"/> <apex:outputField value="{!User.CompanyName}"/> <apex:outputField value="{!User.Phone}"/> <apex:outputField value="{!User.Extension}"/> <apex:outputField value="{!User.Fax}"/> <apex:outputField value="{!User.MobilePhone}"/> <apex:outputField value="{!User.Email}"/> <apex:outputField value="{!User.Street}"/> <apex:outputField value="{!User.City}"/> <apex:outputField value="{!User.State}"/> <apex:outputField value="{!User.PostalCode}"/> <apex:outputField value="{!User.Country}"/> <apex:outputField value="{!User.CurrencyIsoCode}"/> <apex:outputField value="{!User.TimeZoneSidKey}"/> <apex:outputField value="{!User.Account_Sharing__c}"/> <apex:outputLabel value="Enter your name: "/> </apex:pageBlockSection> <apex:pageBlockSection title="Contact Info"> <apex:outputField value="{!User.Contact.Name}"/> <apex:outputField value="{!User.Contact.Email}"/> <apex:outputField value="{!User.Contact.MailingStreet}"/> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
It looks like your controller intends to extend the Case standard controller, but your page claims that your controller is simply a custom controller.
If you intend it to be an extension, then add extensions="CPcontroller" and standardController="Case" to your apex page declaration.
If you intend it to be a custom controller, then remove the argument from your constructor, and either build the new case record from scratch, or pass an id explicitly in the url.
Hello... I don't know why this issue is still showing as I 'edited' this post and renamed it 'CustomController error' Undefined Constructor'. The code is different now and the problem is different. Is it possible for you to take a look at the post under my name from 10/26 entitled 'CustomController error; Undefined Constructor'.
Once again , not sure why this post is showing when it has been edited.
Regards,
This is the issue I posted yesterday.... The custom Controller is trying to take information from the User and Contract object. The error I recieve is :
public class CPcontroller {
/* Used to Display the Contact and User Information to the My Profile view in CP
*/
private final Contact contact;
private final Case c;
private final User user ;
public CPcontroller() {
user = [select id,Name,ContactId,TimeZoneSidKey,Account_Sharing__c, Title, CompanyName,Phone,Extension,Fax,MobilePhone,
Email,Street,City,State,Country,PostalCode,CurrencyIsoCode from User where Id =
:ApexPages.currentPage().getParameters().get('Id')limit 1 ];
contact = [select Id, Name,Email,Phone,Fax,MailingStreet,MailingCity,MailingState,MailingPostalCode,MailingCountry,Title,
ContactAccountName__c from Contact where Id = :user.ContactId limit 1] ;
system.debug('#### ' +user.ContactId);
}
public User getUser() {
return user;
}
public Contact getContact() {
return contact;
}
public PageReference save() {
update user;
update contact;
return null;
}
<apex:page controller="CPcontroller" tabStyle="User">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection title="User Info">
<apex:outputField value="{!User.Name}"/>
<apex:outputField value="{!User.Title}"/>
<apex:outputField value="{!User.CompanyName}"/>
<apex:outputField value="{!User.Phone}"/>
<apex:outputField value="{!User.Extension}"/>
<apex:outputField value="{!User.Fax}"/>
<apex:outputField value="{!User.MobilePhone}"/>
<apex:outputField value="{!User.Email}"/>
<apex:outputField value="{!User.Street}"/>
<apex:outputField value="{!User.City}"/>
<apex:outputField value="{!User.State}"/>
<apex:outputField value="{!User.PostalCode}"/>
<apex:outputField value="{!User.Country}"/>
<apex:outputField value="{!User.CurrencyIsoCode}"/>
<apex:outputField value="{!User.TimeZoneSidKey}"/>
<apex:outputField value="{!User.Account_Sharing__c}"/>
<apex:outputLabel value="Enter your name: "/>
</apex:pageBlockSection>
<apex:pageBlockSection title="Contact Info">
<apex:outputField value="{!User.Contact.Name}"/>
<apex:outputField value="{!User.Contact.Email}"/>
<apex:outputField value="{!User.Contact.MailingStreet}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page
Issue resolved by change VF page to use :
<apex:pageBlockSection title="Contact Info">
<apex:outputField value="{!Contact.Name}"/>
<apex:outputField value="{!Contact.Email}"/>
<apex:outputField value="{!Contact.MailingStreet}"/>
</apex:pageBlockSection>
user = [select id, etc etc, ContactId, Contact.Name, Contact.Email, etc. etc. from User where Id = :ApexPages.currentPage().getParameters().get('Id') limit 1 ]; contact = user.contact;
ah, and vegain: when you post code, if you use the "insert code" feature, your code won't get mangled by the forum software (which has turned every instance of a colon followed by a letter into a face icon).
To use the insert code feature, look at the editing toolbar when you are posting. There's a clipboard that has a "C" on it, just to the right of the bold, italic, underline, and crossout icons. That will open a popup where you can paste code. It will be rendered without any additional formatting (with the html <pre> tag).
Yes, I forgot to use the Insert Code. ... and thank you for the query suggestion.
Regards