You need to sign in to do that
Don't have an account?
Email Trigger on Attachment
I am new to this so I assume this is a pretty simple question. I am trying to develop an e-mail alert that is sent when an Attachment is added to an Account. I am trying to get the Account name in the email. When I receive the email the subject just says: "Attachment Added: name". Attachment and Account are related through parentid, but I am having trouble returning account fields on an Attachment trigger. What am I doing wrong?
trigger Send_email on Attachment (after insert) {
Attachment attach = trigger.new[0];
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {'ja@example.com'};
mail.setToAddresses(toAddresses);
mail.setReplyTo('support@example.com');
mail.setSenderDisplayName('Salesforce Support');
mail.setSubject('Attachment Added : ' + account.name);
mail.setPlainTextBody('work please');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
account doesn't exist in your trigger, therefore when you code "account.name" that means the field "name" assocaited with the sobject type account, not the name of an instance of account.
You'll need to retrieve the account details through SOQL. I'd suggest you do this up front to ensure you won't blow governor limits in the event of a bulk upload.
Something like the following should do it:
All Answers
account doesn't exist in your trigger, therefore when you code "account.name" that means the field "name" assocaited with the sobject type account, not the name of an instance of account.
You'll need to retrieve the account details through SOQL. I'd suggest you do this up front to ensure you won't blow governor limits in the event of a bulk upload.
Something like the following should do it:
Thanks, works perfect!
Would it be possible to trigger an alert when an email fails to pass through the client due to size limitations?
Can you clarify what you mean by the client?
Hi friends,
Can you post the test code of above Trigger...
Regards,
Srikanth
The problem is, I've never used code with Salesforce before. I wouldn't know where to put it and what edits to code would be necessary to include the "New Note" action as well.
Any help would be appreciated.
Thanks,
Shane