• davidCe17ic
  • NEWBIE
  • 0 Points
  • Member since 2010

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies

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;

}

I am new to triggers in SFDC and have created a trigger to flag potential duplicate Cases. I am querying the SuppliedEmail, ContactId and IsClosed values on Cases. It works when a Contact creates a new Case in SFDC when they already have a case open, however if I close/delete,  the potential duplicate case, the checkbox remains ticked. I was trying to use an after insert, after update action but was receiving a System.FinalException: Record is read-only error. Any help is appreciated. 

 

Here is the code:

 

trigger PotentialDupe on Case (before insert, before update) {
List<Case> DupeCases = new List<Case>();
for (Case c : Trigger.new){

Case [] cases = [SELECT id, ContactId, SuppliedEmail, isClosed FROM Case WHERE SuppliedEmail = :c.SuppliedEmail AND ContactId = :c.ContactId AND isClosed = FALSE];

if (cases.size() > 0) {
c.Potential_Duplicate_Case__c = TRUE;
}else
c.Potential_Duplicate_Case__c = FALSE;
}
update DupeCases;
}

I am new to triggers in SFDC and have created a trigger to flag potential duplicate Cases. I am querying the SuppliedEmail, ContactId and IsClosed values on Cases. It works when a Contact creates a new Case in SFDC when they already have a case open, however if I close/delete,  the potential duplicate case, the checkbox remains ticked. I was trying to use an after insert, after update action but was receiving a System.FinalException: Record is read-only error. Any help is appreciated. 

 

Here is the code:

 

trigger PotentialDupe on Case (before insert, before update) {
List<Case> DupeCases = new List<Case>();
for (Case c : Trigger.new){

Case [] cases = [SELECT id, ContactId, SuppliedEmail, isClosed FROM Case WHERE SuppliedEmail = :c.SuppliedEmail AND ContactId = :c.ContactId AND isClosed = FALSE];

if (cases.size() > 0) {
c.Potential_Duplicate_Case__c = TRUE;
}else
c.Potential_Duplicate_Case__c = FALSE;
}
update DupeCases;
}

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;

}