- Home
- Technical Library
- Boards
- Cookbook
- Code Share
- Blogs
- Partners
-
More
-
Services
- Training & Certification
- Support
-
Galleries
- Force.com Sites Gallery
- Chatter Challenge Entries
-
Other Web Sites
- Salesforce.com
- Database.com
- AppExchange
- CRM Community
-
Discussions
- Announcements
- General Development
- Schema Development
- New to Cloud Development
- Apex Code Development
- Visualforce Development
- Formulas & Validation Rules Discussion
- Security
- Mobile
- Force.com Sites
- Chatter Development
- Java Development
- .NET Development
- Perl, PHP, Python & Ruby Development
- Adobe Flash Builder for Force.com
- Desktop Integration
- REST API Integration
- Streaming API
- Visual Workflow
- Apple, Mac and OS X
- VB and Office Development
- Excel Connector
- AJAX Toolkit & S-controls
- Force.com Builder & Native Apps
- AppExchange Directory & Packaging
- Force.com Labs Projects
- Open Source
- Site.com
- Jobs Board - Administrators
- Jobs Board - Developers
- Force.com Discussion Boards
- :
- Developer Boards for Force.com and Database.com
- :
- Apex Code Development
- :
- Salesforce for outlook Creating Cases & separate C...
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Salesforce for outlook Creating Cases & separate Case destinatio ns bringing you down?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
02-24-2012 12:48 PM
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:
- It requires the User to have the Username/Email of the From Address
- The assumption is you have only 1 user with that FromAddress as their email or Username
- 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).From Address.toLowerCase());
system.debug('User: ' + u);
if(mEmail2User.get(mCase2Email.get(lCases[i].id).F romAddress.toLowerCase()) != null){
system.debug('Found User!: ' + mEmail2User.get(mCase2Email.get(lCases[i].id).From Address.toLowerCase()).id);
lCases[i].OwnerID = mEmail2User.get(mCase2Email.get(lCases[i].id).From Address.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');}
}
}

