+ Start a Discussion
clouddev@surashriclouddev@surashri 

DMLOption setting not working

Hi,

I am running below code from sandbox execute anonymous window. I am not getting any mail after execution.
Account a = new Account(name='Acme Plumbing');

insert a;

Contact c = new Contact(email='jplumber@salesforce.com', firstname='Joe',lastname='Plumber', accountid=a.id);

insert c;

Database.DMLOptions dlo = new Database.DMLOptions();

dlo.EmailHeader.triggerAutoResponseEmail = true;

Case ca = new Case(subject='Plumbing Problems', contactid=c.id);

database.insert(ca, dlo);
This is exmaple from Salesforce documentation. Do I have to any setting? Could I request a help?

Thanks,


Vamsi KrishnaVamsi Krishna
Hi,
when you run this code and when the case is created, the email is sent to the email address of the contact associated to the case..
in your sample it will send the email to jplumber@salesforce.com

can you change that to your email and see if it works..
sunil_kumarsunil_kumar
Hi,

You need to specify one more property for DMLOptions.

triggerOtherEmail="Indicates whether to trigger email outside the organization (true) or not (false)"

Also specify your email while contact creation. See below working code:

Account a = new Account(name='Acme Plumbing');
insert a;
Contact c = new Contact(email='Your email id', firstname='Joe',lastname='Plumber', accountid=a.id);
insert c;
Database.DMLOptions dlo = new Database.DMLOptions();
dlo.EmailHeader.triggerAutoResponseEmail = true;
dlo.EmailHeader.triggerOtherEmail =true;
Case ca = new Case(subject='Plumbing Problems11', contactid=c.id);
database.insert(ca, dlo);

If it works, please mark it as solution.

Thanks,
Sunil Kumar
clouddev@surashriclouddev@surashri
Hi,

This has worked. I have one question about mail I received. Is there a possibility to set From address of my choice. In image attached I received mail from rahul.borgaonkar@xxxxxx.com. Is it possible to set it to org wide id and how ?

User-added image

Thanks in advance,

Rahul