You need to sign in to do that
Don't have an account?
bhughes
Email-to-case - Automatically creating a new contact?
We have recently been testing out the Email to Case feature and it seems to fit our basic needs for this functionality.
However, I noticed that when someone not logged in Salesforce as a Contact sends us a support request, it creates the case, but it puts absolutely nothing in the contact area, nor does it record the email address that the email was received from.
Is there a way to create a new contact, or at least store the email address it came from so we know who to reply back to?
Thanks for your help!
However, I noticed that when someone not logged in Salesforce as a Contact sends us a support request, it creates the case, but it puts absolutely nothing in the contact area, nor does it record the email address that the email was received from.
Is there a way to create a new contact, or at least store the email address it came from so we know who to reply back to?
Thanks for your help!
With Email2Case, Salesforce does record the email address and name of the person who opened a Case, even if they are not a Contact.
You should have the Web Name, Web Email, Web Company and Web Phone fields available to you on the Case page layout. If they are not showing up, do a search for any of those fields names in the Help & Training section to get more information. You should also check field level security for the profile of the user that is not seeing those fields.
Hope that helps.
Listing on the AppExchange: https://appexchange.salesforce.com/listingDetail?listingId=a0N30000001R5cyEAC
trigger TriggertoCreateContactformCase on Case (before insert) {
List<String> UseremailAddresses = new List<String>();
//First exclude any cases where the contact is set
for (Case c:Trigger.new) {
if (c.ContactId==null &&
c.SuppliedEmail!=''|| c.SuppliedEmail==null)
{
UseremailAddresses.add(c.SuppliedEmail);
}
}
//Now we have a nice list of all the email addresses. Let's query on it and see how many contacts already exist.
List<Contact> listofallContacts = [Select Id,Email From Contact Where Email in:UseremailAddresses];
Set<String> ExstingEmails = new Set<String>();
for (Contact c:listofallContacts) {
ExstingEmails.add(c.Email);
}
Map<String,Contact> emailToContactMap = new Map<String,Contact>();
List<Case> casesToUpdate = new List<Case>();
for (Case c:Trigger.new) {
if (c.ContactId==null &&
c.SuppliedName!=null &&
c.SuppliedEmail!=null &&
c.SuppliedName!='' &&
!c.SuppliedName.contains('@') &&
c.SuppliedEmail!='' &&
!ExstingEmails.contains(c.SuppliedEmail))
{
//The case was created with a null contact
//Let's make a contact for it
String[] Emailheader = c.SuppliedName.split(' ',2);
if (Emailheader.size() == 2)
{
Contact conts = new Contact(FirstName=Emailheader[0],
LastName=Emailheader[1],
Email=c.SuppliedEmail
);
emailToContactMap.put(c.SuppliedEmail,conts);
casesToUpdate.add(c);
}
}
}
List<Contact> newContacts = emailToContactMap.values();
insert newContacts;
for (Case c:casesToUpdate) {
Contact newContact = emailToContactMap.get(c.SuppliedEmail);
c.ContactId = newContact.Id;
}
}
The Code works great!
However, I am unable to deploy the code from Sandbox to Production. As it only provided code coverage of 54%. Is there anyway to increase the code coverge.
Thanks!