Don't have an account?
Search for an answer or ask a question of the zone or Customer Support.
You need to sign in to do that
Sign in to start searching questions
Signup for a Developer Edition
Sign in to start a discussion
Hi I need help on creating a trigger that fires email when I clone or create a record in a custom object.
Hi ,
we can done on Creation of record. in trigger.
Try this
trigger Customobjectemail on Customobject__c(After Insert)
{
for(Customobject__c co:trigger.new)
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); mail.setToAddresses(co.email__c);//other wise get owner emailid.
// Specify the subject line for your email address. mail.setSubject('SUBJECT');
// Set to True if you want to BCC yourself on the email. mail.setBccSender(false);
// Optionally append the salesforce.com email signature to the email. // The email address of the user executing the Apex Code will be used. mail.setUseSignature(false);
// Specify the text content of the email. mail.setPlainTextBody('hi');//either plain text body (or) Htmlbody.mail.setHtmlBody('<b>Hi</b>');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
There is error if I change my Line 11 to this:
mail.setToAddresses('forseen_destiny@live.com');
Error: Compile Error: Method does not exist or incorrect signature: [Messaging.SingleEmailMessage].setToAddresses(String) at line 11 column 1
string[] toaddress = 'sdff@hhh.com';
mail.setToAddresses(toaddress);
Great thx! If I wanna set my subject with info from my custom object, how do I do that?
just place your custom fields
mail.setsubject('Hi'+co.name+'some text'+co.Customfield__c);
do same like this to body also.
Hi accept my solutions.
Aw thanks man! I owe u a big favor!
Hi ,
we can done on Creation of record. in trigger.
Try this
trigger Customobjectemail on Customobject__c(After Insert)
{
for(Customobject__c co:trigger.new)
{
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(co.email__c);//other wise get owner emailid.
// Specify the subject line for your email address.
mail.setSubject('SUBJECT');
// Set to True if you want to BCC yourself on the email.
mail.setBccSender(false);
// Optionally append the salesforce.com email signature to the email.
// The email address of the user executing the Apex Code will be used.
mail.setUseSignature(false);
// Specify the text content of the email.
mail.setPlainTextBody('hi');//either plain text body (or) Htmlbody.
mail.setHtmlBody('<b>Hi</b>');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
All Answers
Hi ,
we can done on Creation of record. in trigger.
Try this
trigger Customobjectemail on Customobject__c(After Insert)
{
for(Customobject__c co:trigger.new)
{
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(co.email__c);//other wise get owner emailid.
// Specify the subject line for your email address.
mail.setSubject('SUBJECT');
// Set to True if you want to BCC yourself on the email.
mail.setBccSender(false);
// Optionally append the salesforce.com email signature to the email.
// The email address of the user executing the Apex Code will be used.
mail.setUseSignature(false);
// Specify the text content of the email.
mail.setPlainTextBody('hi');//either plain text body (or) Htmlbody.
mail.setHtmlBody('<b>Hi</b>');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
There is error if I change my Line 11 to this:
mail.setToAddresses('forseen_destiny@live.com');
Error: Compile Error: Method does not exist or incorrect signature: [Messaging.SingleEmailMessage].setToAddresses(String) at line 11 column 1
string[] toaddress = 'sdff@hhh.com';
mail.setToAddresses(toaddress);
Great thx! If I wanna set my subject with info from my custom object, how do I do that?
just place your custom fields
mail.setsubject('Hi'+co.name+'some text'+co.Customfield__c);
do same like this to body also.
Hi accept my solutions.
Aw thanks man! I owe u a big favor!