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
DJ 367DJ 367 

how to make ToAddress field mandate in emailMessage object

Hello All,

I have done a trigger which make toAddress mandate. However it is not working my code is here. I checked in debug log is toAddress is blank then salesforce automatically assigns AdditionalTo to toAddress field. is there any way to make it mandate? .Thanks
 
trigger EmailRelatedToIsBlank on EmailMessage (before insert) {
for(EmailMessage eMsg : Trigger.new)
    {
		system.debug('---eMsg.ToAddress--' + eMsg.ToAddress);
		if(eMsg.ToAddress != null){
			
		}else{
			
			eMsg.addError('To Address can not be blank');
		}
			
    }
}



 
Steven NsubugaSteven Nsubuga
trigger EmailRelatedToIsBlank on EmailMessage (before insert) {
for(EmailMessage eMsg : Trigger.new) {
		system.debug('---eMsg.ToAddress--' + eMsg.ToAddress);
		if(eMsg.ToAddress == null || String.isEmpty(eMsg.ToAddress)) {
			eMsg.addError('To Address can not be blank');
		}
    }
}

 
Raj VakatiRaj Vakati
What is the need to trigger here ? You could able to do it simple validation as shown below 


User-added image
Raj VakatiRaj Vakati
Change Condition as shown below 
 
OR (
ISBLANK( ToAddress )  , 
ISNULL(ToAddress )
)

 
Jyotirupa DasJyotirupa Das
Hi Raj,

The above validation is not working in Lightning experience. Could you please suggest.