You need to sign in to do that
Don't have an account?
Trying to add condition to uncheck checkbox when query returns false
This is probably going to be something really simple but I cannot get this to work. I have a piece of code which is checking a checkbox on the case object when a possible duplicate is submitted to SFDC. It does everything it is supposed to however I want to add a condition so when I close out the possible duplicate cases, the query should evaluate to false and the checkbox should be unchecked. Any ideas?
Here is the code so far:
trigger CaseDupeTrigger on Case (before insert, before update)
{
List<Case> c = new List<Case>();
if (Trigger.isInsert)
{
for (Case caseId : Trigger.new){
c = [select id,suppliedemail,isclosed from case where suppliedemail =: caseId.suppliedemail and isclosed=false];
if (c.size() > 0) {
for(Case caseIdOld : c)
caseIdOld.Potential_Duplicate_Case__c=true;
}
}
}
else if (Trigger.isUpdate)
{
for (Case caseId : Trigger.new)
{
Case oldcaseId = Trigger.oldMap.get(caseId.id);
if (caseId.suppliedemail != oldcaseId.suppliedemail)
{
c = [select id, suppliedemail, isclosed from case where suppliedemail =: caseId.suppliedemail and isclosed=false];
if (c.size() > 0)
{
for(Case caseIdOld : c)
caseIdOld.Potential_Duplicate_Case__c=true;
}
}
}
}
if(c.size() > 0)
update c;
}
Thanks for the suggestion Asish.
While syntactically correct (no errors) the original trigger to check the checkbox when a dupe is found is not firing anymore.
Any suggestions?
add System.debug(); and see trigger is fired or not, If fired and again test which block It is entering and which block It is not entering.
So I got the trigger to work again, but adding the additional If statement doesn't work as desired.
When closing out the potential duplicate, the checkbox remains ticked on the non-duplicate.
If(caseId.Status == 'Closed'){ for(Case caseIdOld : c) caseIdOld.Potential_Duplicate_
Case__c=false; }