• jonthepirate
  • 0 Points
  • Member since 2010

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
  • 2

I'm having trouble sending out an email message if I use an adderror. I've read in the apex docs that its not processing since the adderror does not allow the tranaction to commit. Knowing this is the case, what alternatives do I have?


Ultimately, I want to prevent a user from deleting a contact when there are licenses and I also want to be notified that the action has taken place. I think I might have to get creative for this. Here is the trigger I have so far:



trigger PreventDelete on Contact (before delete) {
for (License__c l : [select contact__c from license__c
where contact__c in :Trigger.oldMap.keySet()]) {

//Setup email and send
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {'email@acme.com'};
mail.setSenderDisplayName('Salesforce Support');
mail.setSubject('Contact Deletion Attempted');
mail.setPlainTextBody('A contact delete was attempted.');
mail.setHtmlBody('Review contact for deletion<p>'+
' View license<a href=https://na5.salesforce.com/l.id>click here</a>');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

Trigger.oldMap.get(l.contact__c).addError('Contact has licenses attached. Support has been notified.');





I'm a bit stumped on this. I've created a managed package which includes a hierarchical custom setting at the org level. This is then used in custom formula fields. All works well if you view the pages as a system administrator, but if you login as a standard user all you see is #Error!

I've checked and the fields are set as visible and read only, and the the standard user is set to view the correct page layout. The formula fields display fine if I replace the custom settings part with a string, and of course work fine for sys admins. Where else should I look to make sure standard users have access to this data?

Many thanks!

  • January 25, 2010
  • Like
  • 0