0

i am trying to create a custom object list button but i'm getting an issue "unknown constructor 'sendemailctlr.sendemailctlr()' Markup"

visualforce page

<apex:page standardController="Logistic_Contacts__c" controller="SendEmailCtlr" recordSetVar="Logistic_Contact" action="{!sendEmailToCustomer}">

<apex:form >
<apex:pageblock >
  <apex:pageMessages id="showmsg"></apex:pageMessages>
      <!--<apex:commandButton value="Back" action="{!Cancel}" style="width:90px"/>-->
  </apex:pageblock>
</apex:form>
</apex:page>

apex class

public with sharing class SendEmailCtlr {

private Id SLTcontactid;
Public  Logistic_Contacts__c SLTContact;
public SendEmailCtlr(ApexPages.StandardController controller) {
    SLTcontactid = controller.getId();
    SLTContact=[Select Id, Email_Template_ID__c From Logistic_Contacts__c Where Id=:SLTcontactid]; // change to SLT CONTACT QUERY
}

public PageReference sendEmailToCustomer(){
    String contactId =SLTContact.Logistic_Contact__c;
    Id emailTemplateId=SLTContact.Email_Template_ID__c;
    String SLTCid = SLTContact.id;
    String contactEmail=SLTContact.Logistics_Contact_Email__c;  //EMAIL THAT IT WILL GO TO
    // String emailtemp =System.Label.EmailTemplateID;

    PageReference sendToEmailPage;
         sendToEmailPage = new PageReference('/_ui/core/email/author/EmailAuthor?p2_lkid=' + contactId + '&p3_lkid=' + SLTCid + '&p24='+ contactEmail +'&retURL='+SLTCid+'&rtype=003&template_id=' + emailTemplateId); 

    return sendToEmailPage;
}
}

1 Answer 1

1

Your controller class is written as a controller extension, which uses a constructor along the lines of

public SendEmailCtlr(ApexPages.StandardController controller) {

That seems to be correct, but your Visualforce page is referencing it as if it were a standard controller, with a controller= attribute. Standard controllers use a constructor with no parameters:

public SendEmailCtlr() {

That's why you're getting an "unknown constructor" error. Just change controller= to extensions= and Salesforce will find the "right" constructor.

Additionally, your Visualforce page is declared with a recordSetVar attribute, which implies that you are using a StandardSetController. If you intend to use a set controller, you can change your extension's constructor to

public SendEmailCtlr(ApexPages.StandardSetController controller) {
7
  • Hey, i'm now getting sendemailctlr.sendemailctlr(apexPages.standardsetcontroller.controller)' Markup Commented Feb 22, 2018 at 21:15
  • See updated answer - you'll need to change your constructor signature to reflect your use of a set controller. Note that StandardSetController does not have a getId() method, so you'll get another error there. Commented Feb 22, 2018 at 21:19
  • Brilliant that worked, final question! SLTcontactid = controller.getId(); is no longer working so i'm trying to figure out how to bring through the id still? Commented Feb 22, 2018 at 21:23
  • Set controllers store sets of objects, so they don't have a single Id. Since you're only selecting a single contact, it's not clear to me whether you need to change to using a standard controller, or alter your query - it's a design-level issue. Commented Feb 22, 2018 at 21:26
  • So i want to send an email to all the ticked rows from the list view, i originally didn't have the recordsetvar part but i couldn't see the visualforce page option when creating the button as a list view, if that makes sense? Commented Feb 22, 2018 at 21:30

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.