Unknown constructor'.......(ApexPages.StandardController controller)'
I'm new to Salesforce.
I'm doing a practice problem in which I have to create a Visualforce page to save a contact detail and display that on another VF page.
ContactDetails.vfp :
<apex:page standardController="Contact" extensions="ContactDisplayController">
<apex:form >
<apex:pageBlock title="Add Contact">
<apex:pageBlockSection columns="1">
<apex:inputField value="{! Contact.FirstName }"/>
<apex:inputField value="{! Contact.Lastname }"/>
<apex:inputField value="{! Contact.Phone }" />
<apex:inputField value="{! Contact.Email }" />
<apex:inputField value="{! Contact.Birthdate }" />
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton action="{!saveAndRedirect}" value="Save" />
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
ContactDisplay.vfp :
<apex:page standardController="Contact" extensions="ContactDisplayController">
<apex:form >
<apex:pageBlock title="Display Contact">
<apex:pageBlockSection columns="1">
<apex:outputText value="{! Contact.FirstName }"/>
<apex:outputText value="{! Contact.Lastname }"/>
<apex:outputText value="{! Contact.Phone }" />
<apex:outputText value="{! Contact.Email }" />
<apex:outputText value="{! Contact.Birthdate }" />
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton action="{!redirectToMyVF}" value="Close" />
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
ContactDisplayController.apxc :
public class ContactDisplayController {
public Contact con { get; set; }
public ContactDisplayController(ApexPages.StandardController controller) {
}
public PageReference redirectToMyVF() {
PageReference pref = new PageReference('/apex/Page');
pref.setRedirect(true);
return pref;
}
public PageReference saveAndRedirect() {
if(controller.Save() != null) {
//save your contact record
controller.Save();
//retrieve the contact record
con = ( Contact ) controller.getRecord();
System.debug( con );
//pass the contact id as the URL parameter
PageReference redirectPage = '/ContactDisplay?id=' + con.Id;
return redirectPage;
}
return null;
}
}
When I'm trying to save this code I'm getting error :
Unknown constructor 'ContactDisplayController.ContactDisplayController(ApexPages.StandardController controller)'
Please let me know what is wrong with this code.
I don't think your apex class is saving because it should have a few errors in it and therefore your visual force pages won't be able to locate the extensions constructor.
Update your ContactDisplayController Class to the following and make sure it saves without errors first then save you visual force pages and there should be no error
public class ContactDisplayController {
public Contact con { get; set; }
public ApexPages.StandardController controller {get; set;}
public ContactDisplayController(ApexPages.StandardController controller) {
this.controller = controller;
}
public PageReference redirectToMyVF() {
PageReference pref = new PageReference('/apex/Page');
pref.setRedirect(true);
return pref;
}
public PageReference saveAndRedirect() {
if(controller.Save() != null) {
//save your contact record
controller.Save();
//retrieve the contact record
con = ( Contact ) controller.getRecord();
System.debug( con );
//pass the contact id as the URL parameter
PageReference redirectPage = new PageReference('/apex/ContactDisplay?id=' + con.Id);
return redirectPage;
}
return null;
}
}
Related
attched is my output
enter image description here
Bolow is my visulforce Page and apex page
i am expecting output as a single record in 2 column and has next and previous button to next and previous record.
//apex
public with sharing class MyController
{
public list<Patient__c> objectList = new List<Patient__c>();
public list<Patient__c> currentObject {get; set;}
public integer i;
public MyController(ApexPages.StandardSetController controller) {myAction();}
public string selectedValue {get; set;}
public boolean myBoolean {get; set;}
public void myAction()
{
if ( selectedValue == 'List View') { myBoolean = True; }
else { myBoolean = False ;}
}
public Patient__c getCurrentObject()
{
return currentObject[i];
}
public void goToPrevious(){
if (i>0){i--;}
}
public void goToNext() {
if (i < currentObject.size() - 1) {
i++;
}
}
/* public void goToRecord (Id recordId) {
for (Integer i = 0; i < objectList.size(); i++) {
if (objectList[i].Id == recordId) {
i = i;
break;
}
}
} */
}
Below is my visualforce page code.
<apex:page standardController="Patient__c" extensions="MyController" recordSetVar="Patients">
<apex:pageBlock title="Patient Records...!!!">
<apex:form >
<div align='center' style=' color:blue;font-size:10px '>
Your selection is {!selectedValue}
</div>
<apex:selectList label="View Type" value="{!selectedValue}" size="1">
<apex:selectOption itemvalue="Standared View" itemLabel="Standared View"/>
<apex:selectOption itemvalue="List View" itemLabel="List View"/>
<apex:actionSupport event="onchange" action="{!myAction}" >
</apex:actionSupport>
</apex:selectList>
</apex:form>
<apex:pageBlock rendered="{!myBoolean}">
<apex:pageBlockTable value="{!Patients}" var="Pa" >
<apex:column value="{!Pa.Name}"/>
<apex:column value="{!Pa.Contact_Number__c}"/>
<apex:column value="{!Pa.Email__c}"/>
<apex:column value="{!Pa.Age__c}"/>
</apex:pageBlockTable>
</apex:pageBlock>
<apex:pageBlock title="Standared View" rendered="{!!myBoolean}">
<apex:pageBlockSection columns="2">
<apex:outputField value="{!Patient__c.Name}"/>
<apex:outputField value="{!Patient__c.Age__c}"/>
<apex:outputField value="{!Patient__c.Email__c}"/>
</apex:pageBlockSection>
<apex:form >
<apex:commandButton value="Previous" action="{!goToPrevious}" />
<apex:commandButton value="Next" action="{!goToNext}"/>
</apex:form>
</apex:pageBlock>
</apex:pageBlock>
</apex:page>
I am expecting as a single record showing page where have next and previous button to go net and previous record.
I am new to aura components . I have field where project records are to be displayed .On click of field I should get project records
Desired outputOn click of input field , I should get records like this
Can anyone help me
**Component :**
<aura:component >
<div class="slds-align_absolute-center">
<lightning:layoutItem size="4">
<table> <tr><td style="padding:20px;">
<lightning:input type="sObject" aura:id="test" name="Project" label="Project" value="" placeholder="search project" onClick="{!c.handleClick}"/>
</td></tr>
</table>
</lightning:layoutItem>
</div>
</aura:component>
**Controller :**
public class ListOfProjects {
#AuraEnabled
public static List<project__c> getProjectList() {
List<project__c> myProjects = [SELECT Name from project__c ];
return myProjects;
}
}
**.Js file :**
({
handleClick : function(component, event, helper) {
var action = component.get("c.getProjectList");
action.setCallback(this, function(response) {
console.log(response.getReturnValue());
component.set("v.Projects" ,response.getReturnValue());
});
$A.enqueueAction(action);
}
})
[Required output][1]
[1]: https://i.stack.imgur.com/DQhXw.jpg
You can use lightning:combobox
https://developer.salesforce.com/docs/component-library/bundle/lightning:combobox/example
I need to pass id field value to apex class to delete that row by using command button.
Class:
public class search_delete
{
public string id {get;set;}
public list<account> acc{get;set;}
public search_delete()
{
acc = new list<account>();
acc = [SELECT id,name,phone,industry from account];
}
public void delete_record()
{
acc = [SELECT name,phone,industry from account where id = :id];
delete acc;
}
}
VP:
<apex:page controller="search_delete" >
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!acc}" var="a">
<apex:column value="{!a.Name}"/>
<apex:column value="{!a.Phone}"/>
<apex:column value="{!a.Industry}"/>
<apex:column >
<apex:commandButton value="Delete" Action="{!delete_record}">
<apex:param name="accId" value="{!a.id}"/>
</apex:commandButton>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Now i need to pass id value to apex class from Vp page by the click of delete button.
My Output
use the assignto property of apex command button.
<apex:page controller="search_delete" >
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!acc}" var="a">
<apex:column value="{!a.Name}"/>
<apex:column value="{!a.Phone}"/>
<apex:column value="{!a.Industry}"/>
<apex:column >
<apex:commandButton value="Delete" Action="{!delete_record}">
<apex:param name="accId" value="{!a.id}" assignto="{!idchosen}/>
</apex:commandButton>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
public class search_delete
{
public string id {get;set;}
public string idchosen {get;set;}
public list<account> acc{get;set;}
public search_delete()
{
acc = new list<account>();
acc = [SELECT id,name,phone,industry from account];
}
public void delete_record()
{
acc = [SELECT name,phone,industry from account where id = :idchosen];
delete acc;
}
}
I have a VF page that I can dynamically add rows to a pageBlockTable when clicking a button "Add Participant". I have the page working where I can add the rows, but I'm losing the values in the row when I add a new row. The values get cleared.
Can anyone help on how I can maintain my values when I add new rows? I'm using a wrapper class.
Here is my page:
<apex:page standardController="Call_Report__c" extensions="CallReportControllerExtension" showHeader="true" sidebar="true">
<apex:sectionHeader title="Call Report Edit" subtitle="{!IF(isEditMode, 'New Call Report', CallReportName)}" />
<apex:includeScript value="{!URLFOR($Resource.JQueryUI, '/js/jquery-1.8.2.min.js')}" />
<apex:includeScript value="{!URLFOR($Resource.JQueryUI, '/js/jquery-ui-1.9.0.custom.js')}" />
<script type="text/javascript">
var j$ = jQuery.noConflict();
j$(document).ready(function(){
j$('.errorMsg').hide();
});
</script>
<script>
var newWin=null;
function openLookupPopup(name, id)
{
var url="/apex/ParticipantSearchPopup?namefield=" + name + "&idfield=" + id;
newWin=window.open(url, 'Popup','height=350,width=400,left=100,top=100,resizable=no,scrollbars=yes,toolbar=no,status=no');
if (window.focus)
{
newWin.focus();
}
return false;
}
function closeLookupPopup()
{
if (null!=newWin)
{
newWin.close();
}
}
</script>
<apex:form >
<apex:pageMessages id="Errors" />
<apex:pageBlock title="Call Report Edit" mode="edit">
<apex:pageBlockButtons location="both">
<apex:commandButton action="{!save}" value="Save" id="theSaveButton" />
<apex:commandButton action="{!cancel}" value="Cancel" id="theCancelButton" />
</apex:pageBlockButtons>
<apex:pageBlockSection title="Information" columns="2">
<apex:inputField value="{!Call_Report__c.Name}" required="true" />
<apex:pageBlockSectionItem rendered="{!!isEditMode}" >
<apex:outputLabel value="Owner" />
<apex:outputField value="{!Call_Report__c.Owner.Name}" />
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem rendered="{!isEditMode}" >
<apex:outputLabel value="Owner" />
<apex:outputLabel value="{!$User.FirstName} {!$User.LastName}" />
</apex:pageBlockSectionItem>
<apex:inputField value="{!Call_Report__c.Location__c}" />
<apex:inputField value="{!Call_Report__c.EventAmount__c}" />
</apex:pageBlockSection>
<apex:pageBlockSection title="Detail" columns="1">
<apex:inputTextArea value="{!Call_Report__c.Purpose__c}" cols="75" />
<apex:inputTextArea value="{!Call_Report__c.Results__c}" cols="75" />
<apex:inputTextArea value="{!Call_Report__c.Next_Steps__c}" cols="75" />
<apex:inputField value="{!Call_Report__c.Description__c}" />
</apex:pageBlockSection>
</apex:pageBlock>
<apex:pageBlock >
<apex:pageBlockButtons location="top" id="topButton">
<apex:commandButton id="newButton" value="Add Participant" action="{!addParticipant}" rerender="pageTable" immediate="true" />
</apex:pageBlockButtons>
<apex:pageBlockSection title="Participants" columns="1">
<apex:pageBlockTable id="pageTable" value="{!participantLinesForPage}" var="part">
<apex:column headerValue="Account" width="25%">
<apex:inputHidden value="{!part.participantLine.Account__r.Id}" id="targetAccountId" />
<apex:inputText value="{!part.participantLine.Account__r.Name}" id="targetAccountName" onFocus="this.blur()" disabled="false" style="width:175px;" />
<a href="#" onclick="openLookupPopup('{!$Component.targetAccountName}', '{!$Component.targetAccountId}'); return false" ><img onmouseover="this.className = 'lookupIconOn';this.className = 'lookupIconOn';" onmouseout="this.className = 'lookupIcon';this.className = 'lookupIcon';" onfocus="this.className = 'lookupIconOn';" onblur="this.className = 'lookupIcon';" class="lookupIcon" src="/s.gif" /></a>
</apex:column>
<apex:column headerValue="Contact" width="25%">
<apex:inputHidden value="{!part.participantLine.Contact__r.Id}" id="targetContactId" />
<apex:inputText value="{!part.participantLine.Contact__r.Name}" id="targetContactName" onFocus="this.blur()" disabled="false" style="width:175px;" />
<a href="#" onclick="openLookupPopup('{!$Component.targetContactName}', '{!$Component.targetContactId}'); return false" ><img onmouseover="this.className = 'lookupIconOn';this.className = 'lookupIconOn';" onmouseout="this.className = 'lookupIcon';this.className = 'lookupIcon';" onfocus="this.className = 'lookupIconOn';" onblur="this.className = 'lookupIcon';" class="lookupIcon" src="/s.gif" /></a>
</apex:column>
<apex:column headerValue="User" width="25%">
<apex:inputHidden value="{!part.participantLine.User__r.Id}" id="targetUserId" />
<apex:inputText value="{!part.participantLine.User__r.Name}" id="targetUserName" onFocus="this.blur()" disabled="false" style="width:175px;" />
<a href="#" onclick="openLookupPopup('{!$Component.targetUserName}', '{!$Component.targetUserId}'); return false" ><img onmouseover="this.className = 'lookupIconOn';this.className = 'lookupIconOn';" onmouseout="this.className = 'lookupIcon';this.className = 'lookupIcon';" onfocus="this.className = 'lookupIconOn';" onblur="this.className = 'lookupIcon';" class="lookupIcon" src="/s.gif" /></a>
</apex:column>
<apex:column headerValue="Spent Amount" width="25%">
<apex:inputField value="{!part.participantLine.Spent_Amount__c}" />
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Here is my controller:
public with sharing class CallReportControllerExtension {
private final Call_Report__c callReport;
public Boolean isEditMode {get; set;}
public List<Participants> participantLinesForPage {get; set;}
public CallReportControllerExtension(ApexPages.StandardController stdController) {
this.callReport = (Call_Report__c)stdController.getRecord();
isEditMode = isEditPage(ApexPages.currentPage().getParameters().get('save_new'));
refreshLineItems();
}
public String getCallReportName() {
return [select Name from Call_Report__c where Id =: callReport.Id].Name;
}
public PageReference addParticipant() {
Participant__c newRecord = new Participant__c();
//newRecord.Account__c = '001f0000007qcD5';
//newRecord.Contact__c = '003f0000007H61z';
//newRecord.User__c = '005f0000000U5ME';
//newRecord.Spent_Amount__c = 100.00;
participantLinesForPage.add(new Participants(participantLinesForPage.size(), newRecord));
return null;
}
private void refreshLineItems() {
List<Participant__c> lineItems = [select Account__c, Account__r.Id, Account__r.Name, Contact__c, Contact__r.Id, Contact__r.Name, User__c, User__r.Id, User__r.Name, Spent_Amount__c from Participant__c where Call_Report__c =: callReport.Id];
participantLinesForPage = new List<Participants>();
Integer iterate = 0;
for(Participant__c p : lineItems) {
participantLinesForPage.add(new Participants(iterate, p));
iterate += 1;
}
}
private Boolean isEditPage(String param) {
Boolean retval = false;
if(param != null) {
retval = true;
}
return retval;
}
class Participants {
public Integer iterate {get; set;}
public Participant__c participantLine {get; set;}
public Participants(Integer iterate, Participant__c participantLine) {
this.iterate = iterate;
this.participantLine = participantLine;
}
}
}
The data won't be saved until the save button is clicked, which I haven't implemented yet. I'm just trying to get the values to maintain their state when new rows are added. The refreshLineItems method is clearning the values, but I need that method when records already exist. So, my question is how do I maintain the values in the rows that haven't been saved to the database yet? I was trying to handle it in my wrapper class, but haven't been successful.
Any help is greatly appreciated!
Thanks.
Hi you losing values becouse immediate="true" tag in apex:commandButton.
You can use and "required=false" in inputField instead.
I have a visualforce page with pagination using the standardSetController. On the page, I've also added filtering by status...i.e. new, working, closed, etc. Right now, I'm doing a count() for each status value to display the status count on the page, but that requires a query for each status, which is inefficient. I'd like to get the status counts in a more efficient way.
Here is my controller:
public with sharing class myController {
public ApexPages.StandardSetController setCtrl{get; set;}
public String projId { get; set; }
public String clientName { get; set; }
private List<Ticket__c> TicketList = new List<Ticket__c>();
public myController()
{
projId = ApexPages.currentPage().getParameters().get('id');
clientName = [Select Client__r.Name From Project__c Where Id =: projId].Client__r.Name;
setCtrl = new ApexPages.StandardSetController(Database.getQueryLocator([select Ticket_Number__c, Name, Status__c, Description__c, Description_of_Resolution__c, CreatedDate from Ticket__c Where Project__c =: projId ORDER BY CreatedDate DESC]));
ticketList = (List<Ticket__c>)setCtrl.getRecords();
setCtrl.setPageSize(5);
}
public Integer getNewStatusCount() {
return [select count() from Ticket__c Where Project__c =: projId and status__c = 'New'];
}
public Integer getWorkingStatusCount() {
return [select count() from Ticket__c Where Project__c =: projId and status__c = 'Working'];
}
public Integer getResolvedStatusCount() {
return [select count() from Ticket__c Where Project__c =: projId and status__c = 'Resolved'];
}
public Integer getClosedStatusCount() {
return [select count() from Ticket__c Where Project__c =: projId and status__c = 'Closed'];
}
public Integer getCancelledStatusCount() {
return [select count() from Ticket__c Where Project__c =: projId and status__c = 'Cancelled'];
}
public Integer getReopenedStatusCount() {
return [select count() from Ticket__c Where Project__c =: projId and status__c = 'Reopened'];
}
public Boolean hasNext {
get {
return setCtrl.getHasNext();
}
}
public Boolean hasPrevious {
get {
return setCtrl.getHasPrevious();
}
set;
}
public Integer pageNumber {
get {
return setCtrl.getPageNumber();
}
set;
}
public Integer totalPages {
get {
totalPages = math.ceil((Double)setCtrl.getResultSize() / setCtrl.getPageSize()).intValue();
return totalPages;
}
set;
}
public void first() {
setCtrl.first();
}
public void last() {
setCtrl.last();
}
public void previous() {
setCtrl.previous();
}
public void next() {
setCtrl.next();
}
public List<Ticket__c> getTickets()
{
return (List<Ticket__c>)setCtrl.getRecords();
}
public void filterStatus() {
string myParam = apexpages.currentpage().getparameters().get('myParam');
setCtrl = new ApexPages.StandardSetController(Database.getQueryLocator([select Ticket_Number__c, Name, Status__c, Description__c, Description_of_Resolution__c, CreatedDate from Ticket__c Where Project__c =: projId AND Status__c =: myParam ORDER BY CreatedDate DESC]));
setCtrl.setPageSize(5);
}
}
Here is the VF code:
<div class="contact-form">
<apex:outputPanel id="contactForm">
<apex:form >
<ul class="filteredView">
<li>
<apex:outputLink value="/tickets?id={!projId}">View All</apex:outputLink>
</li>
<li>
({!NewStatusCount})
<apex:commandLink action="{!filterStatus}" value=" New" rerender="contactForm">
<apex:param name="myParam" value="New"/>
</apex:commandLink>
</li>
<li>
({!WorkingStatusCount})
<apex:commandLink action="{!filterStatus}" value=" Working" rerender="contactForm">
<apex:param name="myParam" value="Working"/>
</apex:commandLink>
</li>
<li>
({!ResolvedStatusCount})
<apex:commandLink action="{!filterStatus}" value=" Resolved" rerender="contactForm">
<apex:param name="myParam" value="Resolved"/>
</apex:commandLink>
</li>
<li>
({!ClosedStatusCount})
<apex:commandLink action="{!filterStatus}" value=" Closed" rerender="contactForm">
<apex:param name="myParam" value="Closed"/>
</apex:commandLink>
</li>
<li>
({!CancelledStatusCount})
<apex:commandLink action="{!filterStatus}" value=" Cancelled" rerender="contactForm">
<apex:param name="myParam" value="Cancelled"/>
</apex:commandLink>
</li>
<li id="last">
({!ReopenedStatusCount})
<apex:commandLink action="{!filterStatus}" value=" Reopened" rerender="contactForm">
<apex:param name="myParam" value="Reopened"/>
</apex:commandLink>
</li>
</ul>
<h5>
TICKETS
</h5>
<table width="95%" border="1" cellpadding="5">
<tr align="left">
<th style="width:25px;">Ticket#</th>
<th style="width:200px;">Subject</th>
<th>Description</th>
<th style="width:50px;">Status</th>
<th style="width:75px;"></th>
</tr>
<apex:repeat value="{!tickets}" var="ticket">
<tr>
<td>{!ticket.Ticket_Number__c}</td>
<td>{!ticket.Name}</td>
<td>{!ticket.Description__c}</td>
<td>{!ticket.Status__c}</td>
<td><apex:outputLink value="/detail?id={!projId}&ticketId={!ticket.Id}">View Details</apex:outputLink></td>
</tr>
</apex:repeat>
</table>
<apex:outputPanel rendered="{!(tickets.empty == false)}" styleClass="pagination" >
<ul>
<li><apex:commandLink id="first" value="First" action="{!first}" rendered="{!hasPrevious}" /></li>
<li><apex:commandLink id="prev" value="Prev" action="{!previous}" rendered="{!hasPrevious}" /></li>
<li><apex:commandLink id="next" value="Next" action="{!next}" rendered="{!hasNext}" /></li>
<li><apex:commandLink id="last" value="Last" action="{!last}" rendered="{!hasNext}" /></li>
<li><apex:outputText value="Page {!pageNumber} of {!totalPages}" /></li>
</ul>
</apex:outputPanel>
</apex:form>
</apex:outputPanel>
</div>
</div>
Thanks.
You can get the count of each status for all the status's in a single SOQL query
[select status__c, count(id) from Ticket__c Where Project__c =: projId group by status__c]
You could then expose the results through your existing getter, expose the query results and bind them to the UI via a repeater.