1

I have written a trigger to remove the duplicate insertions but it allows duplications

please check it once where sholu i mistaken

this is my trigger

trigger DuplicateCateCase on Case(before insert,before update) {

     Set<string> accountname= new Set<string>();
     Set<string> integrationtoo= new Set<string>();


     for(Case cas: Trigger.new)
     {
       accountname.add(cas.Account.Name);
       integrationtoo.add(cas.IntegrationTo__c);

     }

   List<Case> duplicatecaseList = [Select id,Case.Account.Name,IntegrationTo__c,SFType__c From Case where Case.Account.Name= :accountname AND IntegrationTo__c =:integrationtoo];

   Set<string > duplicatecaseIds = new Set<string >();

   for(Case dup: duplicatecaseList )
   {
     duplicatecaseIds .add(dup.Account.Name);
      duplicatecaseIds .add(dup.IntegrationTo__c);
      }

   for(Case s : Trigger.new)
   {
        if(s.Account.Name!=null && s.IntegrationTo__c!=null)
        {
           if(duplicatecaseIds.contains(s.Account.Name) && duplicatecaseIds.contains(s.IntegrationTo__c))
           {
             s.addError('Record already exist with same Name');
           }


        }
   }

}

ThAnks

1
  • Please do not ask nearly identical questions over and over again (or open multiple accounts). If you are not getting the answers you desire, please edit your original post for clarity.
    – Adrian Larson
    May 1, 2017 at 14:31

0

Browse other questions tagged .