You need to sign in to do that
Don't have an account?
dev_sfdc1
Case Creation in Trigger
Hi,
I have to customize Email to Case . Please help me.
My scenario is,
If my domain name is filled with values in accounts and based on that email field is filled in Contacts, then I need to create Case through Email to Case.But here my problem is Email is not firing through this trigger.
Trigger UpatestatusonCase on EmailMessage (before insert)
{
List<Contact> lstcon = new List<Contact>();
List<Account> lstacc = [ Select id,Name from Account where Domain_Name__c ='www.techlab.com'];
if(lstacc.size() > 0)
{
lstcon= [Select id,Email,AccountId from Contact where AccountId =: lstacc[0].id and Email = 'tech@techlab.com'];
}
if(lstcon.size() > 0)
{
for(Contact con : lstcon)
{
String stremail = lstcon[0].Email;
List<EmailMessage> em= new List<EmailMessage>();
em=[select id,parentid,FromAddress from EmailMessage where id =: em[0].id and FromAddress =: stremail];
system.debug('1'+em[0].FromAddress);
//String emid = em[0].Parentid;
if(em.size() > 0)
{
system.debug('2passed');
List<Case> cs= new List<Case>();
for(EmailMessage e : em)
{
if(e.FromAddress != '')
{
cs.add(new Case(Subject = e.Subject,Origin = 'Email',Status = 'New',Description = e.TextBody,SuppliedEmail = e.FromAddress));
}
}
insert cs;
}
}
}
}
Thank You
I have to customize Email to Case . Please help me.
My scenario is,
If my domain name is filled with values in accounts and based on that email field is filled in Contacts, then I need to create Case through Email to Case.But here my problem is Email is not firing through this trigger.
Trigger UpatestatusonCase on EmailMessage (before insert)
{
List<Contact> lstcon = new List<Contact>();
List<Account> lstacc = [ Select id,Name from Account where Domain_Name__c ='www.techlab.com'];
if(lstacc.size() > 0)
{
lstcon= [Select id,Email,AccountId from Contact where AccountId =: lstacc[0].id and Email = 'tech@techlab.com'];
}
if(lstcon.size() > 0)
{
for(Contact con : lstcon)
{
String stremail = lstcon[0].Email;
List<EmailMessage> em= new List<EmailMessage>();
em=[select id,parentid,FromAddress from EmailMessage where id =: em[0].id and FromAddress =: stremail];
system.debug('1'+em[0].FromAddress);
//String emid = em[0].Parentid;
if(em.size() > 0)
{
system.debug('2passed');
List<Case> cs= new List<Case>();
for(EmailMessage e : em)
{
if(e.FromAddress != '')
{
cs.add(new Case(Subject = e.Subject,Origin = 'Email',Status = 'New',Description = e.TextBody,SuppliedEmail = e.FromAddress));
}
}
insert cs;
}
}
}
}
Thank You
Hope that helps
Thanks for you reply..But still having same problem.
Please help me.
Thank you.