46

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_locking_records.htm ROW_LOCK issue is very common if you have multiple users updating the record at the same time .Or say a batch job is running and is updating a record and same record another trigger or code snippet (usually a future method) is updating. Account [] ...


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

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


13

I just tested this situation in a developer org - upon deactivation there was no warning/error message stating that the user was an active email service's context user, and the email service itself was not deactivated (at least according to the UI). However, upon sending an email from an authorized source, the handleInboundEmail method of the ...


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

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

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


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

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

I think you might need to set the DMLOptions to trigger autoresponse email. So something like this: Id assignRuleId = [select Id from AssignmentRule where Name = ...].Id; Database.DMLOptions dlo = new Database.DMLOptions(); dlo.assignmentRuleHeader.assignmentRuleId = assignRuleId; //specify assignment rule to tigger //dlo.EmailHeader....


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

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

You can indeed achieve this with an Apex Trigger, however there is also an out of the box or declarative in Force.com speak way to do this. The standard Workflow functionality under Setup > App Setup > Create is where to look for this... This is the basic setup to get an email as shown below...


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

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


4

According to this very recent blog post, this looks like a platform bug, the solution to which is turning off the "Clean" feature in data.com Please leave a comment on this question, as well as this earlier question, if that works. Apparently a few people have run into it.


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