I'm using LiveHelpNow to create Cases and it works fine, I do capture the LiveHelpNow Agent name/SF user Name to a custom field Case.Case_owner__c. However I run a loop to compare it to User object and match it against existing users in SF User Object. Also I check if the case was assigned to Queue I need my Trigger to run after the case got assigned to the queue and replace the Queue owner to the user name I captured and matched with the salesforce user name. code is not giving any error but no Case is being creating. Any Idea?
Note: Im using DmlOption to turn off the case assignment rule for cases only coming for LiveHelpNow.
trigger LiveHelpAfterInsert on Case (after update){
Map<String, Id> cases = new Map<String, Id>();
Set<String> ownerName = new Set<String>();
for(Case record: Trigger.new)
{
if(String.ValueOf(record.OwnerId).startsWith('00G'))
{
cases.put(record.Case_owner__c, null);
ownerName.add(record.Case_owner__c);
}
}
for(User record:[select Id, Name from User where Name IN:cases.keySet()])
{
cases.put(record.Name, record.Id);
}
Database.DMLOptions options = new Database.DMLOptions();
options.AssignmentRuleHeader.useDefaultRule = false;
for(Case record : Trigger.new)
{
record.setOptions(options);
record.OwnerId = cases.get(record.Case_owner__c);
}
}
CTRL + K
.DMLOptions
on a record you are going to perform aDML Operation
on, not one that's mid-transaction.