function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
NavneethNavneeth 

How to send email notification after attachment attached to Account object.

I want to send email notification to user, through trigger or any other way, as soon as the attachment is attached to record in Account object.

Marko LamotMarko Lamot

you should write the trigger

 

trigger TiggerName on attachment (after insert)

            {

                       

.... 

                         

            }

Sfd developerSfd developer

Hi,

 

you should write a trigger like below

 

trigger triggerName on Attachment (after insert) {

Set<Id> accIds = new Set<Id>();
Set<Id> userIds = new Set<Id>();

for (Attachment attach : Trigger.new){
if (acc.ParentId.getsObjectType() == Account.sObjectType){
accIds.add(attach.ParentId);
}
}

if (!accIds.isEmpty()){
for (Account acc : [SELECT Owner FROM Account WHERE Id IN:accIds LIMIT 100]){
userIds.add(acc.Owner);
}

// write you stuff here
}
}

Yoganand GadekarYoganand Gadekar

go through this documentaion for email swnding in apex:

 http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_email_outbound.htm

your trigger should be on attachment object after insert , you should check the object type once this satisfies your criteria fire the emails using email code.

 

thanks,

 

Avidev9Avidev9

Try this.

 

List < Messaging.SingleEmailMessage > allEmails = new List < Messaging.SingleEmailMessage > ();
For(Account acc: [SELECT OwnerId FROM Account WHERE Id IN: accIds LIMIT 100]) {
	String htmlEmailbody = 'Your Message';
    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
    mail.setTargetObjectId(acc.OwnerId);
    mail.setHtmlBody(htmlEmailbody);
    mail.setSaveAsActivity(false);
    allEmails.add(mail);
}
Messaging.sendEmail(allEmails);

 This will help you in sending emails.

 

 

PS: was written on a notepad can have syntax errors