41

http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_locking_statements.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 [] accts = [...


21

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


17

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


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


12

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


10

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


8

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


8

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


8

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


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

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


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

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

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


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

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

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


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.


4

You need to explicitly tell it to use assignment rules and to send the emails using the Database.DMLOptions. Lead l = new Lead(FirstName = 'Joe', LastName = 'Smith', Company = 'XYZ Co'); Database.DMLOptions dmo = new Database.DMLOptions(); dmo.assignmentRuleHeader.useDefaultRule = true; dmo.EmailHeader.triggerUserEmail = true; Database.insert (l, dmo); You ...


4

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(); ...


4

Are you aware of mocking the messaging service? I have an interface with a method sendEmail. In the live code I provide a concrete implementation of the interface which actually sends the email. In the unit test I create a mock implementation of the interface and that implementation can have any logic you want in order to test the various format, if it's ...


4

When SFDC is executing testmethods, it will not send any outbound email. This is for a good reason as testmethods would otherwise run the risk of spamming users. Thus, creating an inbound emailservice to capture the email when running a testmethod will not work as the email is never sent. As @Brian Kessler points out, you can certainly write testmethods to ...


4

There is already a nice blogpost on how to do this http://corycowgill.blogspot.in/2013/12/capturing-signatures-with-html5-canvas.html global with sharing class AnyObjectSignatureController { public AnyObjectSignatureController(){ } @RemoteAction global static String saveSignature(String signatureBody, String parentId) { try{ system.debug('...


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