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
BrianWKBrianWK 

Salesforce for outlook Creating Cases & separate Case destinations bringing you down?

With Spring '12 there's you can now create a case from outlook using the Salesforce for Outlook plugin.

 

This is great, but it can also be a bit frustrating. If you want each indiviual user to have a case "owned" by them after hitting that button, you need to create separate destinations for each user. This means separate configuration for each user. Bleh!

 

So I'm working on a work around. What I've come up with is a Trigger on the EmailMessage. It looks at the FromAddress, grabs the ParentID (case id) and changes the owner to the active Salesforce user with either the Username or Email of the FromAddress. If that fails, it assigns it to the case creator.

 

The gotcha's I've thought of are:

  1. It requires the User to have the Username/Email of the From Address
  2. The assumption is you have only 1 user with that FromAddress as their email or Username
  3. That you want to have it assigned to the Creator if a user isn't found

Here's what I got so far (no test class yet). I appreciate any feedback you have.

 

trigger EmailMessage_CaseCreation on EmailMessage (after insert) {
//Review incoming new cases. If OwnerId = CaseQueue.id then change Owner to CreatedById
    //Name of the queue created
    string QueueName = 'CaseQueue';
    Group CaseQueue = [Select g.Type, g.RelatedId, g.OwnerId, g.Name,g.Id, g.Email  From Group g where g.type = 'Queue' and g.name = :QueueName limit 1];
    set<id> sCaseIDs = new set<id>();
    set<string> sFromAddresses = new set<string>();
    map<id,EmailMessage> mCase2Email = new map<id,EmailMessage>();
    for(integer i=0; i<trigger.new.size(); i++){
        sCaseIds.add(Trigger.new[i].ParentId);
        mCase2Email.put(Trigger.new[i].ParentID, Trigger.new[i]);
        sFromAddresses.add(Trigger.new[i].FromAddress);
    }
    list<Case> lCases = [select id, subject, OwnerId,Createdbyid from Case where id in :sCaseIds];
    if(CaseQueue != null){
        
        if(mCase2Email.size()>0){
            map<string, user> mEmail2User = new map<string, user>();
            For(User u :[Select id, Username, Email From User where IsActive = True and (Username in:sFromAddresses or Email in: sFromAddresses)]){
                system.debug('User added to map: ' + u.email);
                mEmail2User.put(u.email.toLowerCase(), u);
                mEmail2User.put(u.Username.toLowerCase(), u);
            }
            for(integer i=0; i<lCases.size(); i++){
                if(lCases[i].OwnerID == CaseQueue.id){                
                    system.debug('Email From Address is: ' + mCase2Email.get(lCases[i].id).FromAddress);
                    User u = new user(); 
                    u = mEmail2User.get(mCase2Email.get(lCases[i].id).FromAddress.toLowerCase());
                    system.debug('User: ' + u);
                    if(mEmail2User.get(mCase2Email.get(lCases[i].id).FromAddress.toLowerCase()) != null){
                        system.debug('Found User!: ' + mEmail2User.get(mCase2Email.get(lCases[i].id).FromAddress.toLowerCase()).id);  
                        lCases[i].OwnerID = mEmail2User.get(mCase2Email.get(lCases[i].id).FromAddress.toLowerCase()).id;
                    }else{
                        system.debug('Created by: ' + lCases[i].CreatedbyId);
                        lCases[i].OwnerID = lCases[i].CreatedbyId;
                    }
                    system.debug('Owner Changed! ' + lCases[i].OwnerID);
                }
            }
            update lCases;
        }else{system.debug('NO EMAILS FOUND');}
    }
}

 

 

 

nivyajnivyaj

We're running into a similar problem here. There's one more consideration though that really messes things up.Suppose the user selects an email in the sent-email folder vs. the recieved-email  folder. The to and from adress fields get flipped, and then you have a problem!