+ Start a Discussion
ruchika Nayyarruchika 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
Martijn SchwarzerMartijn Schwarzer
Hi Ruchika,

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.
lalitaroralalitarora
Hi Rukchika,

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. 
ruchika Nayyarruchika Nayyar
hi please hlp me for this code

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 });
       

}
        }
    }
}