8

Hi You are getting the error because you are using Messaging.renderStoredEmailTemplate() in for loop as this is counted towards the SOQL governor limit as one query. To avoid the exception you have to remove out Messaging.renderStoredEmailTemplate() of for loop. For more reference please have a look on salesforce docs for the Messaging class. Executing ...


7

Rishi Golyan correctly identified the issue, however, Messaging.renderStoredEmailTemplate() works on single ids rather than a list of ids. So, simply moving that method call to be outside of your loop isn't going to cut it if you have more than 100 Contacts to mail to. One way to handle that situation would be to put it into a class that implements ...


7

The error message can be a little confusing, but this error can be thrown if your main object (relatedTo in your template) doesn't have the "Allow Activities" option checked. Checking this option will solve this issue. This error message should be modified to something like "SaveSetAsActivity is not supported on objects that do not allow activities."


6

EmailMessage is only available for organizations that use Email-to-Case or Enhanced Email, which is automatically enabled for most customers. If you want to be able to relate Email Message records to other objects (besides cases), then it is recommended that you enable Enhanced Email. It means that EmailMessage can be used for other objects as well other ...


5

Your expression is almost correct. I would use <a.+<\/a>. You don't know if href will be the first property (or if there will be multiple spaces after a), and you don't want to skip links that don't conform to your definition if you can avoid it. Another thing you need to correct is to actually instantiate a Pattern (not a Matcher). Pattern ...


5

You can't get the Id on the same transaction because the email messages are sent after the transaction succeeds. See items 19 and 20 on the Triggers and Order of Execution: Commits all DML operations to the database. Executes post-commit logic, such as sending email. Email messages are then generated after the final commit. I think you can ...


4

You need to set the Incomng field to true. See the documentation: Field Incoming Type boolean Properties Create, Defaulted on create, Filter Description Indicates whether the email was received (true) or sent (false).


4

Note: Some of the following is conclusions my team reached for which we could not find explicit documentation; Salesforce support eventually confirmed our findings, just this past week. The EmailMessage object does not have any explicit CRUD or Sharing Settings. There is also no EmailMessage__Share object, so Apex sharing is off the table. With no ...


4

According to the documentation for the EmailMessage Object, this field can only be set on insert not update


3

Line 12 seems to be List attachmentsToInsert = new List(); witch cannot throw that error. Since the error message says the trace is from a trigger and I don't see anything in your code to execute the trigger.... The next logical line that could throw the error would be String theId = ApexPages.currentPage().getParameters().get('id'); If the trigger ...


3

You might want to use the XmlStreamReader class instead. Basically, you just loop through the stream, watching for href attribute. Something like this: XmlStreamReader reader = new XmlStreamReader(xmlString); while(reader.hasNext()) { reader.next(); if(reader.getEventType() == XmlTag.START_ELEMENT && reader.getLocalName() == 'a') { ...


3

Originally, EmailMessage was only available for use with the Case object. The ParentId represents the Case the email is associated with. Now that email messages are available for use with other objects, the RelatedToId represents any object the EmailMessage is associated with (including Case). See the Object Reference for Case to learn more.


3

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


3

It's not the line breaks that are the problem, it's how HTML treats line breaks by default (white-space: normal), which collapses multiple white space characters (space, tab, new line, and carriage return) into single white spaces. There are two general methods for fixing this. CSS The easiest way to fix the problem would be to use CSS: <div style="...


3

There is not currently a way to capture this. The updating of EmailMessage.Status from 0 (New) to 1 (Read) that occurs when a user opens the message does not fire triggers. You can vote to change this on the IdeaExchange.


3

There are some things that are impossible to test in Salesforce. Things like field history and email tasks are generated during the "transaction finalization" step of a transaction, which occurs only after the transaction has run to completion and Salesforce is ready to permanently commit changes to the database. As you've observed, this happens to ...


2

You need to set OW email address here. Administer >Email Administration > Organization-Wide Email Addresses. For the WF you need to set default WF email address under Workflow>Setting. Hope this helps.


2

You can use the below test class : To insert opportunityLineItem, we have to insert opportunity, product etc. Take help from the below code. Let me know if you have any issues @isTest private class Test_demoTrigger { static testMethod void myUnitTest() { // TO DO: implement unit test Test.starttest(); Account acc = new Account()...


2

I had the same problem before and came up with a solution. Basically, you can append the table to your setHtmlBody text value by passing in a list of records (be sure to change to appropriate sObjectType). public static string getTableEmailBody(List<Lead> myList){ String htmlBody = ''; //open table.. htmlBody = '<table border="1" ...


2

Sethu I did think about this and here is a condensed answer Given that an incoming EmailMessage may not have any Attachments, then a trigger on Attachment won't work as it would never fire if an attachment-less EmailMessage arrived. A trigger on EmailMessage wouldn't work as it would miss the attachments added after the EmailMessage trigger executed So, ...


2

I've figured out that this deployment error comes from including this related list metadata in the layouts/EmailMessage-Email Message Layout.layout file: <relatedLists> <fields>NAME</fields> <fields>TYPE</fields> <relatedList>RelatedEmailMessagePeopleList</relatedList> </...


2

Running a deploy from the same repository to a different target org did not generate the error; for now, I'm chalking this up as a platform quirk specific to the one org. EDIT: We refreshed the org that was generating this issue, and the error disappeared; however, it eventually reappeared. Frustratingly, it reappeared seemingly out of nowhere - I made a ...


2

The only way to do this is to: Create and send an instance of SingleEmailMessage populating it with fields of the draft. Create a new EmailMessage with the Sent status (= 3) with fields copied from the draft. Delete the old draft Emailmessage.


2

The following answer is based on crop1645's comment to the question: trigger CaseAttachment on Attachment (after insert) { Set<Id> Parents = new Set<Id>(); List<Attachment> newFiles = new List<Attachment>(); for (attachment a : Trigger.New) { Parents.add(a.parentId); } for (EmailMessage e : [SELECT Id, ...


2

Due to an unidentified issue in my organization, some EmailMessage records were created without some references, and even I, as administrator, couldn't delete or read the records by the UI. I could see them on the developer console, when executing a query, but couldn't change them in any way. The workaround that was proposed (and I took it) was to enable &...


2

You need to enable the Enhanced Email feature in order to use that field in apex. Also, if you want to relate the email message with a User, Lead or Contact, you need to use the EmailMessageRelation object.


2

Best solution I've seen so far is a scheduled apex class that just goes through all cases and updates status rather than relying on a trigger.


2

If we activate Enhanced Email then only Related To field is available, otherwise not. Parent Id is always be available in EmailMessage object. Enhanced Email elevates email to a standard Salesforce object, with customization options and an API. Emails are no longer stored as tasks, but as full-featured records, complete with details, related lists, and ...


2

Figured out the issue. I didn't test by sending and replying to the Proxy email designated in the email-to-case setting. It also requires the setting of including the thread ID in the subject or body also located in the Email-to-case setting.


2

For objects other than Lead and Contact The before trigger on EmailMessage should include a value for RelatedToId which is the parent of the email message (e.g., the Opportunity.Id). Your trigger will need to requery to get values from the Opportunity and do so in a bulkified manner. Note that EmailMessage.RelatedToId is polymorphic and not every ...


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