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.
- I have created a unique text field on case object.
- I have created a workflow rule with field update action
- In formula i have passed
formula:
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){
accountname.add(cas.Account.Name);
integrationto.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 =: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