Account field and integration__c fields combination of record is have already in case object don't allows duplication if sftype__C checkbox is true otherwise allows if sftype__c is false allows for duplication.

  1. I have created a unique text field on case object.
  2. I have created a workflow rule with field update action
  3. In formula i have passed


  Account.Name & IntegrationTo__c  & IF(SfType__c, 'TRUE', 'FALSE')

and activate the workflow rule

but the case object allows the duplicate values anyone suggest right formula to achieve the above requirement.

This is my trigger but this is also allows duplicates please check it once

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

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

         for(Case cas: Trigger.new){



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

       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)){

                  if(s.SFType__c = true){

                      s.addError('Record already exist with same Service');



Thanks in Advance

  • @thanks for quick replying yes. i searched in google for some reference i found one like that
    – Srikar
    May 2, 2017 at 4:31

1 Answer 1


Your use case will not be serve like that way, if you are making a unique field and updating the value based on checkbox indicator.

As because think about a scenario, first time checkbox is false and you are making an update, it will create a value like Account.Name & IntegrationTo__c & 'FALSE' and next time also based on same checkbox as false condition it will try to create same Account.Name & IntegrationTo__c & 'FALSE' and you will receive error due of uniqueness. which you don't want.

I will suggest that, remove uniqueness of the field and update like this from workflow:

Account.Name & IntegrationTo__c

Create a before insert trigger which will check the uniqueness of the record to be inserted based on checkbox condition.

Validation rule will not work here because validation rule is executed first followed by workflow rule.

  • I have updated my question with trigger but it also allows duplicates please check it once
    – Srikar
    May 2, 2017 at 4:42
  • you may refactor the code, also use if (s.SFType__c) instead of if(s.SFType__c = true), otherwise it will always assigned to true May 2, 2017 at 5:03
  • i changed as you said but it the trigger isn't working properly
    – Srikar
    May 2, 2017 at 5:11
  • from yesterday i'm fighting with this Santanu anyway thanks.
    – Srikar
    May 2, 2017 at 5:15

You must log in to answer this question.

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