function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Smita HodiggeriSmita Hodiggeri 

Stop Case assignment rule from running when case is created with particular field value

Hi Community,
 
I am working on a requirement where in I don't want Case assignment rule to run which is changing the case owner.The condition being if there is a value in a particular field (Old case number field which means this case is actually getting unarchived). This is basically a scenario of unarchiving(using ob archiver tool ) where in, upon unarchiving we are loosing original case owner as case assignment rules are running again.
 
Any ideas on how to implement this?
 
My ultimate intention is to preserve case owner. Have the same owner assigned to case as it was before archiving.
 
I read a post which says implement this in future method. I would prefer any non code/low code ways to do this.
https://salesforce.stackexchange.com/questions/186702/turn-off-case-assignment-rules
 
Would a after insert trigger help?
 
Thanks in advance,
Smita
SubratSubrat (Salesforce Developers) 
Hello Smita ,

If you prefer to use Code, you can write an after insert trigger to update the Owner ID field with the existing owner ID when the Old Case Number field has a value.

Here's an example of how the trigger code might look:
trigger PreserveCaseOwner on Case (after insert) {
    List<Id> caseIds = new List<Id>();
    for(Case c : Trigger.new){
        if(c.Old_Case_Number__c != null){
            caseIds.add(c.Id);
        }
    }
    
    List<Case> casesToUpdate = [SELECT Id, OwnerId, Old_Owner_Id__c FROM Case WHERE Id IN :caseIds];
    for(Case c : casesToUpdate){
        c.OwnerId = c.Old_Owner_Id__c;
    }
    
    update casesToUpdate;
}
In this trigger, we are checking if the Old Case Number field is not null and then updating the Owner ID field with the value from the Old Owner ID field.

Hope this helps !
Thank you.
Smita HodiggeriSmita Hodiggeri
Hi @Subrat Thank you for the reply. I tried updated code but I get an error saying " Failed to insert records to SF.  Error from SF: {'success': False, 'errors': [{'statusCode': 'DUPLICATE_VALUE', 'message': 'DUPLICATE_VALUE:duplicate value found: <unknown> duplicates value on record with id: <unknown>', 'fields': []}], 'sobject_type': 'EntitySubscription', 'old_id': '0E80k000000TO8PCAW'}
My Udpated code. 
trigger preserveCaseOwner on Case (before insert) {
    List<Id> caseIds = new List<Id>();
    for(Case c : Trigger.new){
        if(c.original_number__c != null){
            c.Old_Owner_Id__c =c.OwnerId;
            caseIds.add(c.Id);
        }
    }
   
    List<Case> casesToUpdate = [SELECT Id, OwnerId, Old_Owner_Id__c FROM Case WHERE Id IN :caseIds];
    for(Case c : casesToUpdate){
        c.OwnerId = c.Old_Owner_Id__c;
    }
   
    update casesToUpdate;
}