Skip to main content
Tweeted twitter.com/StackSalesforce/status/754791560420659200
added 88 characters in body
Source Link
Adrian Larson
  • 151.3k
  • 38
  • 247
  • 431

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);           
    } 
}

}

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);           
} 

}

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);           
    } 
}
Source Link
Templar
  • 175
  • 2
  • 13

Trigger change ownership of case from Q to User after Turning off Case Assignment Rule

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);           
} 

}