You need to sign in to do that
Don't have an account?
Smurfet15
Email to case field population from user object
Hi Guro,
We have an email to case setup, and we want populate field on case based on the related email fromaddress, since email address will be the lookup to user object then populated the rest of the field then save the case. I have tried to create the trigger with below logic and i am getting an error(invalid type: email) on the "set<email> = new set<email>()" tag.
Can you please help mo on this code?
----------------------------------
trigger Fieldpopulation on Case (before insert) {
List<Case> C = trigger.new;
List<EmailMessage> EMessage = [Select id, FromAddress, parentid
From EmailMessage
where parentid in :C];
//assigning the email address
Set<email> fromadd = new Set<email>(); //getting error here
for( EmailMessage EM: EMessage )
{
fromadd.add( EMessage.FromAddress );
}
//Select in the user object to populate Requestor data
List <User> ulist = [Select id, name, email, Department, Sales_Office__c, Phone
from user
where email = :fromAdd ];
// Update the Case
c.loc_name__c = ulist.name;
c.loc_email__c = ulist.email;
c.loc_Dept__c = ulist.Department;
update c;
}
Thanks in advance.
We have an email to case setup, and we want populate field on case based on the related email fromaddress, since email address will be the lookup to user object then populated the rest of the field then save the case. I have tried to create the trigger with below logic and i am getting an error(invalid type: email) on the "set<email> = new set<email>()" tag.
Can you please help mo on this code?
----------------------------------
trigger Fieldpopulation on Case (before insert) {
List<Case> C = trigger.new;
List<EmailMessage> EMessage = [Select id, FromAddress, parentid
From EmailMessage
where parentid in :C];
//assigning the email address
Set<email> fromadd = new Set<email>(); //getting error here
for( EmailMessage EM: EMessage )
{
fromadd.add( EMessage.FromAddress );
}
//Select in the user object to populate Requestor data
List <User> ulist = [Select id, name, email, Department, Sales_Office__c, Phone
from user
where email = :fromAdd ];
// Update the Case
c.loc_name__c = ulist.name;
c.loc_email__c = ulist.email;
c.loc_Dept__c = ulist.Department;
update c;
}
Thanks in advance.
Set<String> fromadd = new Set<String>();
I did try that but error now is here:
//assigning the email address
Set<string> fromadd = new Set<string>();
for( EmailMessage EM: EMessage ) // error : Initial term of field expression must be a concrete SObject: List<EmailMessage>
{
fromadd.add( EMessage.FromAddress );
}
----------
on the User object email field and EmailMessage fromaddress has both email type.
Mary
To solve the compile error, do this:
You're going to have problems after that code though because c is actually a List<Case> and not a single Case. You need to use some maps to hold values and then do loops to update records correctly. See http://sfdc.arrowpointe.com/2008/09/13/bulkifying-a-trigger-an-example/ for an example of how that might look.