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
Ashmi PatelAshmi Patel 

Invalid type: UtilException

this is my class code..
And getting this error
plz help...
thnx


public with sharing class SendTemplatedEmail{
public static void sendTemplatedEmail(String[] toRecipients, String[] ccRecipients,
                          String templateApiName, ID targetObjId, Id whatId, ID orgWideEmailId,
                          Boolean saveAsActivity, Attachment[] attachList )
 {
 
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
    
Id templateId;  
try {templateId = [select id, name from EmailTemplate where developername = : templateApiName].id;}
catch (Exception e) {
  throw new UtilException ('[U-03] Unable to locate EmailTemplate using name: ' + templateApiName +
                ' refer to Setup | Communications Templates ' + templateApiName);
}
    
    
    email.setToAddresses(toRecipients);
    email.setCcAddresses(ccRecipients);
    email.setTargetObjectId(targetObjId);
    email.setWhatId(whatId);
    email.setorgWideEmailAddressId(orgWideEmailId);
    email.setTemplateId(templateId);
    email.setSaveAsActivity(saveAsActivity);      
    
    System.debug(LoggingLevel.INFO,'** entered sendTemplatedEmail, to:' + toRecipients + ' cc:' + ccRecipients +  ' templateId:' + templateId + ' tagetObjId:' + targetObjId +
                    ' whatId:' + whatId + ' orgWideEmailId: ' + orgWideEmailId);
    try {
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
        return;
    }
    catch (EmailException e) {throw new UtilException('[U-02] sendTemplatedEmail error. ' + e.getMessage());}
 
}  
}
 
bob_buzzardbob_buzzard
This error suggests that you haven't defined the custom class 'UtilException' - is it available in your codebase?