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
Kalpana DhanajayarajKalpana Dhanajayaraj 

Method not working

Public static void validateCase(List<case> cases){
     for(Case c: cases){
      if((c.recordTypeid == Label.RT_Deal_Support && c.Type == 'Insight Tag Implementation') && (String.isBlank(c.contact.Name) || c.Top_Level_Domain__c == null))
         {
            c.addError('Top-Level Domain and Contact Name are required when Record type = Deal Support and Type = Insight Tag Implementation');
         }
       }
    }


 calling the above method via trigger 
trigger CaseTrigger on Case (before insert, before update, after insert, after update, after delete, after undelete) {
    if(GeneralUtil.triggerOverrideCheck('CaseTrigger')){
        if(Trigger.isBefore){
            CaseUtil.validateCase(Trigger.new);


I created a case of record type 'Deal Support'  and Type = Insight Tag Implementation.
And did not enter value for Contact name and Top-level domain.
But the error was not thrown.


 
bob_buzzardbob_buzzard
Is your label RT_Deal_Support definitely correct? 

Also, although I don't think this is the issue, the related contact record won't be populated on the trigger, so c.contact.Name won't contain a value. You should check the id in that situation.

I suggest you add some debug statements to your trigger to confirm the record ids/string values are correct.
Lokeswara ReddyLokeswara Reddy
Update your condition to check against blank('') values for the field c.Top_Level_Domain__c, it is always better ro check against both null and blank('').

one more point not related this issue, Trigger context is available in the apex method, no need to pass Trigger.new while invoking apex method from trigger.