0

I have validation rule need to be implemented by validation rule.

Issue object is child object of Case in Master Detail Relationship. If Primary Issue(Checkbox) is checked then Status in Case record cannot be changed to "Closed" and this case with Specific Record Type this trigger should work.

Even the system.debug is not working mentioned in trigger

Please help me out with this one.

I have pasted my code below guys please let me know any error in code.

trigger Cares_Case on Case (before insert, before update) {
    if (Trigger.isBefore){
        if(Trigger.isInsert && Trigger.isUpdate){
            WM_Cares_Trigger_Handler.CaseClosedPrimaryCheckValidaionrule(Trigger.new);
            System.debug('Cares Trigger done');
        }
    }
}
public class Cares_Trigger_Handler {
    public static void CaseClosedPrimaryCheckValidaionrule(List<Case> newcaselist){
        for(Case triggeredcase :newcaselist){
            if(triggeredcase.Status == 'Closed' && triggeredcase.RecordType.DeveloperName == 'Cares'){
                if(triggeredcase.Issue__r.Primary_Issue__c = true){
                    triggeredcase.addError('Case not closed If Primary Issue is checked');  
                }
            }
        }
    }
}
2
  • Two things stand out for me: 1) The class you've shared is Cares_Trigger_Handler but your trigger is using WM_Cares_Trigger_Handler. 2) triggeredcase.RecordType.DeveloperName is going to be null because records in trigger context variables do not contain related data. If you need to use more than one period/dot/full-stop, then you need to query for it (alternatively, you could bring that information into your Case records by making a formula field).
    – Derek F
    Commented Sep 29, 2023 at 16:44
  • Also, triggeredcase.Issue__r.Primary_Issue__c will be null for the same reason as #2 in my previous comment. Issue__c being a child of Case means that you'll need to iterate over the child records (you need to query for them, of course). Otherwise you'll get a syntax error about how Primary_Issue__c isn't a member variable of a List. Also also, your equality check for primary issue needs to be == (equality) and not = (assignment).
    – Derek F
    Commented Sep 29, 2023 at 16:53

1 Answer 1

1

In Your trigger you are adding condition with AND(&&) Operator which can't possible.

Same record can't be in Trigger.isInsert && Trigger.isUpdate and it should be Trigger.isInsert || Trigger.isUpdate.

trigger Cares_Case on Case (before insert, before update) {
    if (Trigger.isBefore){
        if(Trigger.isInsert || Trigger.isUpdate){
            WM_Cares_Trigger_Handler.CaseClosedPrimaryCheckValidaionrule(Trigger.new);
            System.debug('Cares Trigger done');
        }
    }
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .