Hot answers tagged

58

To do this you must first set up a dedicated email address by navigating to Setup -> Administration Setup -> Email Administration -> Organization-Wide Addresses menu. Once you have created an org-wide address (note that Salesforce will require you to confirm the address prior to using it, so if you're going to be sending things from a junk address it would ...


23

Update 26th Oct: See below for a second version following comments below I have just promoted this idea as well, I would never have imagined it to be a good design for this method to have it throw an unhandled exception, IMHO that is! Anyway, since we are being inventive here, the following also seems to do the trick. But be aware much like the custom ...


23

You can use the Limits.getEmailInvocations method . Test.startTest(); methodThatSendsEmail(); Integer invocations = Limits.getEmailInvocations(); Test.stopTest(); system.assertEquals(1, invocations, 'An email should be sent'); What to do about NO_MASS_MAIL_PERMISSION? You can use the Messaging.sendEmail method with the optional allOrNone ...


19

What MassEmailMessage appears to give you is a more optimal coding route if you are focusing on sending to Contacts, Leads or Users relating to either Contract, Case, Opportunity or Product objects. So if you had 50 such Contacts to email you need only have a single MassEmailMessage instance and set a list of those Id's into it. Instead of creating 50 ...


19

Per the Governor Limits, you can only send 5000 single emails a day (or less, depending on license). Using the API or Apex, you can send single emails to a maximum of 5,000 external email addresses per day based on Greenwich Mean Time (GMT). Single emails sent using the Salesforce application don't count toward this limit. There’s no limit on ...


18

Now we can use setTreatTargetObjectAsRecipient(treatAsRecipient) and treatAsRecipient as false. https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_email_outbound_single.htm


15

Have a look under Setup | Email Administration | Deliverability. Newly created sandboxes have the default email deliverability set to "System email only." The options are: No access: Prevents all outbound email to and from users. System email only: Allows only automatically generated emails, such as new user and password reset emails. All email: Allows all ...


14

I see several things happening here. First, there's an issue with the following: setCcAddresses(ccAddresses) Optional. A list of carbon copy (CC) addresses. The maximum allowed is 25. This argument is allowed only when a template is NOT used. As you're using a template, this obviously causing an issue for you. Next, it sounds as though you want your ...


13

One of the packaged apps mentioned in other answers may well be the easiest option, but it's pretty straightforward to create an Email Service in Apex. The sample code in the docs creates a Contact and a Task; here is code to create a Lead instead: global class CreateLeadExample implements Messaging.InboundEmailHandler { global Messaging....


13

The idea thread mentioned by @crmprogdev is now realized. As of winter 15 there is now programmatic access to content deliveries. ContentDistribution cd = new ContentDistribution(); cd.name = 'test'; cd.ContentVersionId = '12312132abad'; cd.PreferencesAllowOriginalDownload = false; cd.PreferencesAllowPDFDownload = false; cd.PreferencesAllowViewInBrowser = ...


12

There are some AppExchange apps that do this, or you can create an Email Service (under Develop, in Setup) to do the same. There's VCS Smart Email, Email to Lead, and I think Marketo does it as well. Honestly, though, if I were doing it, I would just create an Email Service.


12

The Limits class as you have started to discover is only for the current request and does not provide any org wide limit information. Salesforce have partially addressed this with emails, but as far as I can see there is nothing for Batch Apex or @future. Though I have included some thoughts below on both. Emails. There is a couple of methods on the ...


12

Try validating cc and bcc addressess by checking null or empty if(emailCCAddress != null && emailCCAddress.trim() != ''){ Ccaddress = emailCCAddress.split(',',0); mail.setCcAddresses(ccaddress); } if(emailBCCAddress != null && emailBCCAddress.trim() != ''){ Bccaddress = emailBCCAddress.split(',',0); ...


12

This was an issue on a project I worked on as well. This particular feature is not very admin friendly (as you found out the hard way:). We chose to uncheck the "Send welcome email" box under Communities > Administration > Emails. We then created a workflow rule on the User object to send out the welcome email to new community users. The workflow rule ...


11

We did notice this as well, however we tend to now use Subscriber support to login and reproduce the issue. If you login via Subscriber support you can see the stack traces and full debug information for you packages. Take a look at the answer to this question for more information about the Subscriber Support feature, it's a must for an ISV!


11

The only way to modify the From line of a mail is by using the mail.setOrgWideEmailAddressId(ID) which requires the ID of an Organization-Wide Address record defined in Your Name | Setup | Email Administration | Organization-Wide Addresses Org wide addresses let you specify both the Display Name and the Email Address in From line of your outgoing mails. ...


11

From the Salesforce.com Help Docs Newly created sandboxes have the default email deliverability setting System email only.To configure email deliverability settings, in the sandbox organization, click Your Name | Setup | Email Administration | Deliverability. If editable, set the Access level in the Access to Send Email section. You may not be able to ...


10

So the issues turns out to be the DML options. In order for e-mails to get sent - even from Assignment Rules, the DML option has to be updated: dmlOpts.EmailHeader.TriggerUserEmail = true; Otherwise it will ignore any email trying to be sent internally that is not called by apex directly.


10

In order to change the link URL for the New Email button, you have to use a Javascript hack. Create a new "narrow" Homepage Component (really a Sidebar component, but SFDC calls them Homepage components) and paste the following code in (be sure to check off Show HTML first, so that this is entered as code, not as text) <div id="remove-shortcut-id"> ...


10

Here is my attempt to combine all of the answers given, and to interpret the SF Documentation provided on email limits. A SINGLE_EMAIL_LIMIT_EXCEEDED exception is thrown when the daily Messaging.SingleEmailMessage limit is exceeded. This exception can be thrown in other cases as well, like when email deliverability is not set correctly. Each ...


10

This is an internal only route, that currently is NOT supported. It should not be used in production environments. The route has no ownership internally, and could stop working without notice.


9

what do you actually want to test? the execution of the code or that the message gets delivered? how about you delegate it to a separate method sendNotication() which you can test independently. furthermore you can test it via console as well batch class global class MyBatch implements Database.Batchable<sObject> { // BATCH CONTRACT ... ...


9

Salesforce.com has specifically prevented us developers from having an easy time using the standard interface to send emails without user intervention. We can create a link to go to the Send Email page, but the user still has to click on Send to send the email. Here's the link: /_ui/core/email/author/EmailAuthor?p2_lkid={!Contact.Id}&rtype=003&...


9

The EmailMessage object ParentId is exclusive to Cases (at least based on current Salesforce schema information). You can always branch your code to inspect the ParentId with the Case object prefix value (500). To my knowledge, your solution of adding a trigger on EmailMessage is the only viable solution.


9

By design, Salesforce will not send any outbound email while executing tests. This is to prevent you from accidentally spamming people (or yourself) during tests. This does however make it difficult to properly test your code as it is best practice to not test for code coverage, but for all logical branches. The way that I have worked around this is to ...


9

The likely answer comes from the comment by @MarcDBehr Email Services can have several Email Addresses. Each Email Address has a context user (i.e. running user) You need to enable debug logging for that Context User. Well-designed email services do not use a specific individual as the Context user, rather, some dedicated headless user that serves as a ...


9

TL;DR - Doesn't seem to be available. So the object in question here is LogSearchResult. I found this SObjectType by looking at the link to one of these logs. It looked like: https://instance.salesforce.com/servlet/servlet.FileDownload?file=0BR000000000000 So then I plugged that in to my time tested strategy: system.debug(Id.valueOf('0BR000000000000')....


9

It should instead be: List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>(); for Opportunity record : records) { Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage() // set properties on singular email emails.add(email); } Messaging.sendEmail(emails);


9

Logging an unsub event is the way to get unsubscribes logged properly (and ultimately in the _Unsubscribe data view). You can't insert into directly into any of the data views. You'd need jobID, listID, _JobSubscriberBatchID and an encrypted or obfuscated _subscriberkey to replicate what's done on a one-click unsubscribe page. You may be able to pass and ...


9

You cannot create a triggered send definition with the UI if you are using the Transactional Messaging API. You need to create your definition via the REST API in order for this to work.


Only top voted, non community-wiki answers of a minimum length are eligible