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

cant create the case via customer portal



I have enabled the customer portal and configured it.


I also created the trigger which sends the notification when the case is created either via email or customer portal.


The following is my trigger code,

trigger mailNotification on Case ( after insert) {
    contact CaseContact;
    for(case Cases{
                    //Fetch the related case contact.
          Messaging.SingleEmailMessage CaseNotificationmail = new Messaging.SingleEmailMessage

          if (CaseContact!= null){ 
          CaseContact = [SELECT Email FROM Contact WHERE Id = :Cases.ContactId];                 

                if (CaseContact != null && CaseContact.Email != null) {
    CaseNotificationmail.setToAddresses(new List<string> {CaseContact.Email});
    } }
    else {
    CaseNotificationmail.setToAddresses(new List<string> {Cases.SuppliedEmail});
    CaseNotificationmail.setSenderDisplayName('Salesforce Support');
    CaseNotificationmail.setSubject('New Case Created : ' + Cases.CaseNumber);
    CaseNotificationmail.setPlainTextBody('Your case:<b> ' + Cases.CaseNumber +' has been 

created.'+'To view your case <a href='+case.Id);
    Messaging.sendEmail(new Messaging.SingleEmailMessage[] { CaseNotificationmail });



When I used this trigger, I cant create the new case by customer portal.


It shows the following error


Error: Invalid Data.

Review all error messages below to correct your data.
Apex trigger mailNotification caused an unexpected exception, contact your administrator: mailNotification: execution of AfterInsert caused by: System.EmailException: SendEmail failed. First exception on row 0; first error: INVALID_EMAIL_ADDRESS, Invalid to address : null: []: Trigger.mailNotification: line 20, column 1"


If i am using workflow rules , I will not include the sepecified address for reply.


Can anybody help to solve this problem?






Hi Ambiga,


The error seems to point that the email address is not being identified - I checked the following doc wheich shows replyto email in double quotes -


Could you try this and let me knwo if that helps..


Hi AmbigaRam,


After looking at the exception you got, I believe you should add null check contion at below snippet of code


 else {
if(Cases.SuppliedEmail!=null) CaseNotificationmail.setToAddresses(new List<string> {Cases.SuppliedEmail}); }