You need to sign in to do that
Don't have an account?
ruchika Nayyar
Once an account an email should go to the admin user with specified text below. An account has been created and name is "Account Name".
trigger Account2 on Account (before insert) {
List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
for (Account myAccount : Trigger.new) {
if (myAccount.Email != null && myAccount.FirstName = "AccountName") {
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
List<String> sendTo = new List<String>();
sendTo.add(00528000002VHIK.Email);
mail.setSubject('An account has been created');
String body = 'Dear ' + myAccount.FirstName + ', ';
body += 'An account has been created and name is "AccountName"';
}
Messaging.sendEmail(mails);
}
}
please help me for this code
List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
for (Account myAccount : Trigger.new) {
if (myAccount.Email != null && myAccount.FirstName = "AccountName") {
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
List<String> sendTo = new List<String>();
sendTo.add(00528000002VHIK.Email);
mail.setSubject('An account has been created');
String body = 'Dear ' + myAccount.FirstName + ', ';
body += 'An account has been created and name is "AccountName"';
}
Messaging.sendEmail(mails);
}
}
please help me for this code
You can use workflow rules to accomplish this. Please check the following link for an example of how to do this:
https://www.youtube.com/watch?v=fhG2kG1Z1xQ
You will want to create an email template for this purpose and send it to the admin user once a new Account has been created.
Hope this helps!
Best regards,
Martijn Schwärzer
Ps. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.
I believe Martijn Suggested well on this. Workflow will do in your case, and just a add on to Martijn's Answer, We should not use SF Ids in the code as when code deploy to higher orgs(Test, Prod) Id changes.
i want to create this
Once an account an email should go to the admin user with specified text below.
An account has been created and name is "Account Name".
trigger emailtoadmin on Account (before insert) {
for(Account acc:trigger.new){
{
if(acc.myruchika__email1__c!= null)
{
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
email.setToAddresses(new String[]{'ruchikanayyar12@gmail.com'});
email.setReplyTo('ruchika Nayyar');
email.setSenderDisplayName('CRM');
email.setSubject('Welcome');
email.setBccSender(false);
email.setUseSignature(false);
email.setPlainTextBody('An account has been created and name is "Account Name".');
email.saveAsActivity = false;
email.setTargetObjectId(acc.Id);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email });
}
}
}
}
trigger sendEmailToAdmin on Account (after insert){
List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
User userObj=[select Id,Profile.Name,Email from user where Profile.Name='System Administrator'];
for(Account accObj:Trigger.new){
if(userObj.Email!=null){
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setSenderDisplayName('Salesforce');
//mail.setUseSignature(false);
//mail.setBccSender(false);
//mail.setSaveAsActivity(false);
//Assigning the receiver Mail Address
mail.toAddresses = new String[]{userObj.Email};
mail.setSubject('New Account was Created.');
String body = 'Dear System Administrator, <br/>';
body += 'An account has been created and name is '+accObj.Name+'.';
mail.setHtmlBody(body);
mails.add(mail);
}
}
if(!mails.isEmpty()){
Messaging.sendEmail(mails);
}
}