+ Start a Discussion
MariPMariP 

"Error: Compile Error: Method does not exist or incorrect signature..." when compile my trigger

Hi everybody !

I'm rather inexperienced on Sales Force developments in general, an on Apex particulary...

I want to send emails via a trigger after update.

 

Here is the trigger :

 

trigger CSR_CORE_RequestAfterUpdate on Request__c (after update) {
    //codes executed by spoon
     if(UserInfo.getName()== 'SPOON Consulting' || UserInfo.getName()== 'Stephane Tiger'){
        System.debug('## Start CSR_CORE_RequestAfterUpdate'+ UserInfo.getName()); 
        
        Map<Id, Request__c> mpReqStatus = new Map<Id, Request__c> ();//
        Map<Id, List<Id>> mpReqSLA = new Map<Id, List<Id>> ();
        List<Id> lstReqSLAIds;  
        Set<id> slaIds = new Set<Id>();//old sla ids
        
        List<Request__c> requestList =new List<Request__c>();//list to be used for inserting milestone alerts
        Boolean requestAdded =false;
        
        for(Integer i = 0;i<trigger.new.size();i++){
            if(trigger.new[i].Call_type__c == UTI_Constants.callType_In_Request){           
                
                lstReqSLAIds = new List<Id>();                  
                //assuming whenever a case is closed...alerts are only invalidated not generated. so taking into consideration onlytrigger.old[i].SLAs 
                
                
                if((trigger.new[i].SLA_1__c != trigger.old[i].SLA_1__c ) ||(trigger.new[i].Status__c != trigger.old[i].Status__c) ){//trigger.new[i].Status__c == UTI_Constants.status_Closed_Request
                    System.debug('## adding sla1s for ' + trigger.new[i].Request_Type__c);                  
                    requestList.add(trigger.new[i]);
                    requestAdded=true;
                    if( trigger.old[i].SLA_1__c != null){
                        System.debug('## adding sla1 to invalidate alert if old sla 1 is not null' + trigger.new[i].Request_Type__c); 
                        slaIds.add(trigger.old[i].SLA_1__c);
                        lstReqSLAIds.add(trigger.old[i].SLA_1__c);
                    }
                }       
                    
                System.debug( '## SLA2s differ ');
                if((trigger.new[i].SLA_2__c != trigger.old[i].SLA_2__c)|| (trigger.new[i].Status__c != trigger.old[i].Status__c)){//trigger.new[i].Status__c == UTI_Constants.status_Closed_Request 
                    System.debug('## adding sla2 for ' + trigger.new[i].Request_Type__c); 
                    if( trigger.old[i].SLA_2__c != null){//to invalidate milestone alerts, need to check if old SLA is not null
                        System.debug('## adding sla2 to invalidate alert if old sla 2 is not null' + trigger.new[i].Request_Type__c); 
                        slaIds.add(trigger.old[i].SLA_2__c);
                        lstReqSLAIds.add(trigger.old[i].SLA_2__c);
                    }
                    
                    if(!requestAdded){
                        System.debug( '## Request added to list already');
                        requestList.add(trigger.new[i]);
                    }
                }                           
                    
                if(!lstReqSLAIds.isEmpty()){
                    System.debug('## adding slas to list ');
                    mpReqSLA.put(trigger.old[i].id,lstReqSLAIds);
                    mpReqStatus.put(trigger.old[i].id,trigger.old[i]);
                    System.debug('## added slas to list  ' +mpReqSLA +' reqStatus' +mpReqStatus);
                }
            }       
            
        }
        //invalidates existing alerts...
        if(mpReqSLA.size() > 0 && mpReqStatus.size() > 0)  {
            System.debug('## call the method invalidateMilestoneAlerts accordingly');
            UTI_CORE_AlertTriggers.invalidateMilestoneAlerts(slaIds, mpReqStatus, mpReqSLA);
        }
        
        //inserting alerts
        if(requestList.size() > 0)  {
            System.debug('## call the method InsertMilestoneAlerts accordingly');
            UTI_CORE_AlertTriggers.insertMilestoneAlerts(requestList);
        }
          
        System.debug('## End CSR_CORE_RequestAfterUpdate'+ UserInfo.getName()); 
     }

    //codes executed by MCP
     if(UserInfo.getName()== 'Marie-Christine PIEL'){
     
        List<Request__c> closedRequestList =new List<Request__c>();//list for which send an email
        
        for(Integer i = 0;i<trigger.new.size();i++){
            if(trigger.new[i].Call_type__c == UTI_Constants.callType_In_Request){  
                if ((trigger.new[i].Status__c != trigger.old[i].Status__c) && 
                (trigger.new[i].Status__c =='CORE_Closed')) {
                closedRequestList.add(trigger.new[i]);
                }
               }
            }
        if(closedRequestList.size() > 0)  {
          CSR_CORE_RequestTriggers_SendSingleEmail.SendEmail(closedRequestList);
        }
        }
}

 I'm only concerned with the code inside the test on my profile, at the end.

 

And here is my class :

public with sharing class CSR_CORE_RequestTriggers_SendSingleEmail {

// Objets
public Request__c oRequest {get;set;}
public Contact_external__c oContact_external {get;set;}
public Contact oContact {get;set;}

// Collections
public list<string> lEmailAddressesList {get;set;}
public list<string> lTypesContactList {get;set;}


public void SendEmail(List<Request__c> closedRequestList){
	
	for (Request__c closedRequest:closedRequestList){

// GET EMAIL ADDRESSES
	
	Boolean resultTest;
	
	//put values of multi-select picklist field into a list
		list<string> lTypesContactList = closedRequest.Contact_types_for_Email__c.split(';', 15);
	
	// for every type of contact of the list, find its email address in Contact external
	     Integer count = 0 ;
	     while (lTypesContactList [count] != null) {
		
	     Contact_external__c acc_Contact_External  = [select Email__c from Contact_external__c 
	    	 where Account__c = :closedRequest.Entity__c 
	     and title__c = :lTypesContactList[count] limit 1 ];
	     	// it is an external contact
			 if(acc_Contact_External.email__c != null){
			     lEmailAddressesList[count] = acc_Contact_External.email__c; 
			     count++ ;
			     // not found in external contact
		  		 } //else {
		  		 	//resultTest = lTypesContactList[count].contains('laner');
		  		 	// is it a planer ?
		  		 	//if(resultTest == true ) {
		  		 	//	Contact acc_Contact = [select email from Contact
		  		 	//	where Contact.Id = Account.  
		  		 	//                                                     +
		  		 	                                                                
		  		 	//}
		  		 //}
	     }

	// add email of the contact chosen if there is one 
		 if(closedRequest.Other_contact_for_Email__c!=null){
		 Contact acc_Contact = [select Email from Contact 
		 where Id = :closedRequest.Other_contact_for_Email__c limit 1 ];
		 count++ ;  
		 } 

	// put emails in a STRING field with ';' for separator
	     count = 0 ;
	     String emailAddresses = ' ';
	     while (lEmailAddressesList [count] != null) {
	     emailAddresses = emailAddresses + lEmailAddressesList[count] ; 
	     emailAddresses = emailAddresses + '; ' ;
	     count++ ;
  		 }

	// add user free field to that field 	
		 emailAddresses = emailAddresses + closedRequest.Others_email_addresses__c;
	
// SEND THE EMAIL

	// Reserve email capacity for this transaction 
	Messaging.reserveSingleEmailCapacity(2);
	
	// pour liste des erreurs d'envoi si plantage    
	List<Messaging.SendEmailResult> results = new list<Messaging.SendEmailResult>();
	
	// create a new single email message object  
	Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
	
	// Strings to hold the email addresses to which you are sending the email
	String[] bccAddresses = new String[] {emailAddresses};	
	
	// Assign the addresses for the To, CC and BCC lists to the mail object.  
	email.setBccAddresses(bccAddresses);
	
	// Specify the address used when the recipients reply to the email.   
	email.setReplyTo('support@acme.com');
	
	// Specify the name used as the display name.  
	email.setSenderDisplayName('Salesforce Support???');
	
	// Specify the subject line for your email address.  
	email.setSubject('The request has been closed : ' + closedRequest.Id);
	
	// Set to True if you want to BCC yourself on the email.  
	email.setBccSender(false);
	
	// Optionally append the salesforce.com email signature to the email.  
	// The email address of the user executing the Apex Code will be used.  
	email.setUseSignature(false);
		
	// value of setTargetObjectId must be Id of a contact, a lead or a user
	//email.setTargetObjectId()
	
	// value of setWhatId must be Id of an account, asset, campaign, case, .....            
	//email.setWhatId(candidat);
	    
    // The email template ID used for the email : NO : not if BCC used
    // email.setTemplateId('00XD0000001Vdq1');
                        
    
	// Specify the text content of the email.  
	//email.setPlainTextBody('Your Case: ' + case.Id +' has been created');
	
	// mail.setHtmlBody('Your case:<b> ' + case.Id +' </b>has been created<p>'+
    //  ' View case <a href=https://na1.salesforce.com/'+case.Id+'>click here</a>');
	
	email.setHtmlBody('The request:<b> ' + closedRequest.Id +' </b>has been closed<p>'+
	     ' Here is the answer :<b> ' + closedRequest.Answer__c +' </b><p>');

	email.setSaveAsActivity(false);
	
	// Send the email you have created.  
	Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email });
  
	}			 
}

}

 

When I compile the trigger, I get this message :Error: Compile Error: Method does not exist or incorrect signature: CSR_CORE_RequestTriggers_SendSingleEmail.SendEmail(LIST<Request__c>) at line 85 column 11

 

I can't find why..

I need help !!!

Marie


 

 

Best Answer chosen by Admin (Salesforce Developers) 
SteveBowerSteveBower

This:

 

CSR_CORE_RequestTriggers_SendSingleEmail.SendEmail(closedRequestList);

 

 

is an invocation of the SendEmail method on your class CSR_Core_RequestTriggers_SendSingleEmail (call it "X")

 

However, nowhere in your trigger do you instantiate an instance of X from which you can call the method.  If you were to do:

 

CSR_CORE_RequestTriggers_SendSingleEmail X = new CSR_CORE_RequestTriggers_SendSingleEmail();
X.SendEmail(closedRequestList);

then this seems like it what you were shooting for.

 

 

However, if you don't want to have to instantiate your CSR_...etc. class, you can look into defining Static methods to define a true utility class. 

 

Best, Steve.

 

All Answers

SteveBowerSteveBower

This:

 

CSR_CORE_RequestTriggers_SendSingleEmail.SendEmail(closedRequestList);

 

 

is an invocation of the SendEmail method on your class CSR_Core_RequestTriggers_SendSingleEmail (call it "X")

 

However, nowhere in your trigger do you instantiate an instance of X from which you can call the method.  If you were to do:

 

CSR_CORE_RequestTriggers_SendSingleEmail X = new CSR_CORE_RequestTriggers_SendSingleEmail();
X.SendEmail(closedRequestList);

then this seems like it what you were shooting for.

 

 

However, if you don't want to have to instantiate your CSR_...etc. class, you can look into defining Static methods to define a true utility class. 

 

Best, Steve.

 

This was selected as the best answer
MariPMariP

Thank you, Steve, it's great !

My trigger is compiled.....