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');
}
}
}
}
}
Cares_Trigger_Handler
but your trigger is usingWM_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 yourCase
records by making a formula field).triggeredcase.Issue__r.Primary_Issue__c
will be null for the same reason as #2 in my previous comment.Issue__c
being a child ofCase
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 howPrimary_Issue__c
isn't a member variable of aList
. Also also, your equality check for primary issue needs to be==
(equality) and not=
(assignment).