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
Trail Header 4Trail Header 4 

Assign the Case to the user (which is dynamic) mentioned in one of the fields on Case

According to salesforce's standard functionality,while creating Case, Case gets assigned by Case Assignments Rules. If Case Assignment Rule fails, Case gets assigned to default Case Owner. I either do not want this. I want to assign the Case to the user mentioned in one of the fields on Case, which is dynamic. I have already tried with process builder and before insert trigger, but in both cases, Case gets assigned to default owner. Can someone suggest me any solution?
DevADSDevADS
Hey Trall Header,

Try below code, It should work -
trigger CaseTrigger on Case (before insert,before update) {
        
    for(case caseItr : Trigger.new){
        caseItr.ownerId = caseItr.Backup_CST__c;  //Backup_CST__c => custom field on case
    }
}

Hope this resolves your issue.
Happy coding!
Ramakrishna Reddy GouniRamakrishna Reddy Gouni
simply case assignment rules should be in order like 1, 2,3,4....... , create one more rule for specific user and put it at last. it works just like if else if control statement.  if fail all conditions then final else condition will be execute. i.e your specific user.
 
Trail Header 4Trail Header 4
Thanks @DevADS.
The code assigns the user correctly but since Assignment Rules executes after the trigger, the user again gets changed with default case owner.
Trail Header 4Trail Header 4
Thanks @Ramakrishna.
I do not want to assign the Case to specific user. It will be dynamic. Case Assignment Rules doesn't provide option to set users dynamically.
DevADSDevADS
1. Create a boolean field on case object
2. Set it to true in the trigger
trigger CaseTrigger on Case (before insert) {
        
    for(case caseItr : Trigger.new){
        caseItr.ownerId = caseItr.Backup_CST__c;  //Backup_CST__c => custom field on case
        caseItr.<booleanfield> = true; // Update code with the boolean field API name

    }
}
3.Add a rule criteria in assignment rule like below-
User-added image

Hit this as a best answer if it resolves your issue.