function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Vegaln1Vegaln1 

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>

 

 

 

 

ShikibuShikibu

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. 

Vegaln1Vegaln1

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,

Message Edited by Vegaln1 on 10-27-2009 05:51 AM
Message Edited by Vegaln1 on 10-27-2009 05:51 AM
Vegaln1Vegaln1

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 :

 

 

SObject row was retrieved via SOQL without querying the requested field: User.Contact The controller code is below followed by the VF page  Once again, sorry for the confusion....

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;
}

 

 VF page:

<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

 


Message Edited by Vegaln1 on 10-27-2009 06:00 AM
Vegaln1Vegaln1

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>

ShikibuShikibu
You can perform your query in one operation. You have to explicitly query the related fields you'll want, like this:

 

 

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;

 

 

 

 

ShikibuShikibu

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).

Vegaln1Vegaln1

Yes, I forgot to use the Insert Code. ... and thank you for the query suggestion.

 

Regards