48

Salesforce platform has a feature ROW LEVEL Security. This feature ensures that sharing and visibility set by salesforce administrators for the records have to be maintained. As a part of this feature, there are sharing calculations that the platform has to perform when the record ownership is changed or child records are created/modified. Assume that a ...


25

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 ...


20

You need to use JAVA-like CASE_INSENSITIVE pattern (?i) Something like this: Pattern staPattern = Pattern.compile('(?i)STA[0-9]{4}');


13

When requested from a valid session (i.e. after someone has logged in to salesforce) this URL (that includes the ID of the attachment) works: /servlet/servlet.FileDownload?file=00PM0000001fH6h If you create a text formula field on an object of this form: HYPERLINK('/servlet/servlet.FileDownload?file=' + AttachmentId__c, 'View', '_blank') the link can be ...


11

After speaking to Salesforce support I have resolved the issue. Rather than delete the post i will answer it incase anyone has similar issues... The support consultant literally took a copy of my class, deleted it from the system and reinstated it again. After doing this the class became compatible with the Email Service despite no code changing. I ...


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

The email to case is a java process that reads all of the data in the email and then assigns pieces to various fields in SF and then does an Insert or Upsert into the SF system. Because the email is completely handled 'behind your firewall' and the data is directly inserted into SF, some people consider this a bit 'safer'. You also get more flexibility since ...


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 ...


8

To answer the specific question, the sendEmail method returns a list of Messaging.SendEmailResult objects. This list will be in the same order as the corresponding list of emails provided to sendEmail(..). As Mohith pointed out, you can only discover whether the email message was successfully queued for delivery, and, if not, why. You can't discover if the ...


8

With respect to your edited question, as @AdrianLarson answered, your schedulable class still doesn't run until immediately after Test.stopTest(). Asserting the change in Limits.getEmailInvocations() should be sufficient for your requirements. That being said, to answer the question you asked me on how to query the Messaging.SendEmailResult, that's ...


8

Add this line: newContentVersion.firstPublishLocationId= user.Id; A more detailed explanation: When documents are created via apex (contentversion object), you need to specify the library otherwise they will always be created in private library of the context user. Since you are querying a random user (and probably this user is not the context user of ...


7

You can't get the PDF content unfortunately. While Email Services do run under a 'Context User', you will notice that UserInfo.getSessionId() returns null from any InboundEmailHandler implementation you may have. The HTML with JavaScript is serving up a client-side redirect to a Salesforce login page. This is because pdf.getContent() runs in a different ...


7

2 options: Option 1 1) Create a class which implements the inboundHandler. global class VerifyOrgWideEmailAddress implements Messaging.InboundEmailHandler { global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) { Messaging.InboundEmailResult result = new Messaging....


6

This error is because the method notification.setTargetObjectId(usr.Id) uses User Id and as per documentation you need to use notification.setWhatId(updatedOpp.Id) only when setTargetObjectId is contact. Refer documentation below http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_Messaging_SingleEmailMessage_setWhatId.htm If you specify ...


6

Email Services are one way to do this. Given the following example, you'd be able to send an email whose subject is the Account Id, body is the Account Name, and it would update accordingly: create a new Apex class "AccountUpdateEmailHandler" containing this code: global class AccountUpdateEmailHandler implements Messaging.InboundEmailHandler { global ...


6

You can do this natively in Apex using the Zippex library which is open source. https://github.com/pdalcol/Zippex Your code would be similar to this: Blob zipBlob; //This needs to contain the zip file Zippex myZip = new Zippex(zipBlob); //Loop through the files in Zip and process them for (String fileName : myZip.getFileNames()) { Blob fileData = ...


6

As @crop1645 mentioned, the error message is fairly clear in this case. When you specify the Org-Wide Email Address you're sending the message from, you will not be able to also set the Sender Display Name. Your code example should work correctly after you remove this line: conformemail.setSenderDisplayName('Ramesh');


6

In your EmailServices class, you have this line: @testVisible Opportunity opp = new Opportunity(); You are apparently trying to query the value of this variable in your testmethod to see if it is accurate. Instead, you need to do this: Messaging.InboundEmailResult result = objconfirm.handleInboundEmail(email, envelope); System.assertEquals( result.success ...


6

Since backslashes are the escape character in Apex string literals, if you want a literal backlash, you need to escape it with a backslash. So the right regex to use would be \\{.*\\}


5

In addition to the other answers, there is ApexMocks and the fflib Enterprise Pattern - specifically the Unit of Work Layer Here's an example: First, the class/method that sends the email: public void sendEmail() { fflib_ISobjectOfWork uow = Application.UnitOfWork.newInstance(); Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); ...


5

On-demand email to case is a good option if you know Email attachments (if any) won't be greater than 25MB in size You are not concerned about keeping the emails traffic within your firewall You won't be required to install an email-to-case agent behind your firewall For further clarification, you may want to play a little with each of them by using them ...


5

This is as per Yahoo's DMARC policy. I presume you are getting a response similar to this This message was created automatically by the mail system. A message that you sent could not be delivered to one or more of its recipients. This is a permanent error. The following address(es) failed: testthis@yahoo.com (...


5

opp is an array, and you're trying to use it like a single record. You actually meant to write: String[] bccEmail = new String[]{opp[0].owner.email};


5

You tried to use the result of SOQL query in your code, but this result is not guarantied. In some case your query can return null. So, when you tried to use null.Email you got this error. To fix it you need to check that query has returned an actual result. User user1 = [SELECT Email FROM User WHERE ID=: mycontact.Rep_abv__r....


5

The EmailStatus object is not queryable directly (please vote for this idea), but it can be queried indirectly from Leads and Contacts as a child relationship sub-query as noted by Jenny Bennett on this other stackexchange answer. Leads with EmailStatuses SELECT id, name, ( SELECT id, taskId, createdDate, firstOpenDate, ...


5

This is how I solved the problem, after saving off the attachments then I updated the message body to replace the cid references with URL to the files. For some magical reason, Salesforce will properly format the reply in a way that the inline images appear. This solution is inspired by Bhawani Sharma. There are two files: 1. EmailUtils 2. ...


5

Salesforce files have superseded attachments. A single attachment can have only one parent and access to attachments is controlled by the parent record. If we want to attach same file on two different records then we would need to upload that attachment to a new record thus consume extra storage and having redundant files. The same two limitations are ...


5

I think you can set the status value with the sequence number. 0 - New 1 - Read 2 - Replied 3 - Sent 4 - Forwarded 5 - Draft So it could be like this EmailMessage emailMessage = new EmailMessage(); emailMessage.status = '3'; // email was sent


5

From what I understand, You don't need to create a task to insert an EmailMessage. Email message has relatedToId field which you can use to directly link it to any desired record. As relatedToId is polymorphic like ParentId for Attachments, you should be fine. Source: https://developer.salesforce.com/docs/atlas.en-us.212.0.api.meta/api/...


5

You need to turn on multi-line mode in order for the $ specifier to match at a line terminator (rather than at the end of the string). Multi-line mode is activated with the token (?m). As Derek F. alluded to in a comment, you'll also need to use the find() method (rather than matches()) in order to identify a substring match. Here's a sample using your ...


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