• Olavo Alexandrino
  • 0 Points
  • Member since 2021

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
  • 4

I am trying to create a before-insert trigger on EmailMessage, so that when a user logs an email from the Outlook Integration, I can set the RelatedToId field based on the email sender (FromAddress).

What I am finding in my testing, however, is that both FromAddress and ValidatedFromAddress are NULL on insert! Perhaps due to how the Outlook Integration inserts email records - perhaps it follows up the insert with an update to populate the FromAddress field.

Unfortunately, I must put my logic in the before-insert - you are only allowed to set RelatedToId on insert.

(1) Do any of you have more details around the behavior of the Outlook Integration and the From fields that might help me?

(2) Can anyone see another solution to be able to programmatically set the RelatedToId for tracked emails, based on the sender, other than my approach of the before-insert trigger on EmailMessage?

I have considered moving my logic to an after insert, and trying to delete the original email and recreate it with all the right information, but that seems extreme and I am concerned about the impact the changing id (due to delete and create new) will have on the Outlook Integration.

Thanks to all for any help you can provide!
Scott Kostojohn
We are trying to show '<' and '>' character in feeditem body. But we are getting invalid markup error while inserting the feeditem.body.

String is <test>

public static void createRFAFeedEntry(List<Request_for_Assistance__c> newRFA){
        List<FeedItem> feedItemsList = new List<FeedItem>();
        for(Request_for_Assistance__c req : newRFA) {
                FeedItem post = new FeedItem();
                FeedItem post_sec = new FeedItem();
                post.ParentId = req.id;
                post.createdById = req.createdbyid;
                String fullFileURL = URL.getSalesforceBaseUrl().toExternalForm()+'/'+ req.id;
                String stringURL  = '<a href='+fullFileURL+' >'+req.Name+'</a>';
                post.LinkUrl = fullFileURL ;
                post.Title = 'Created '+req.Name;
                post.Visibility = 'InternalUsers';
               String summ=String.valueof(req.Summary__c);
               String escapeString = summ.escapeHtml3();
               string escapeString1=escapeString.unescapeHtml3();
               /* String sum1 =String.valueof(req.Summary__c) ;
                String target1 = '<';
                String target2='>';
                String replacement1 = '{';
                String replacement2 = '}';
                String sum2 = sum1.replace(target1, replacement1);
                //system.debug('test string***'+sum2);
                String summary = sum2.replace(target2, replacement2);
                //system.debug('test string***'+summary);
                String pdd1 =String.valueof(req.Problem_Description_and_Definition__c);
                String target11 = '<';
                String target21='>';
                String pdd2 = pdd1.replace(target11, replacement1);
                //system.debug('test string***'+pdd2);
                String pdd = pdd2.replace(target21, replacement2);
                //system.debug('test string***'+summary);
                //post.Body =  'Created Date - '+req.CreatedDate+'\nSummary - '+req.Summary__c +'\nProblem Description and Definition - '+req.Problem_Description_and_Definition__c;
              post.Body =  'Created Date - '+req.CreatedDate+'\nSummary - '+ escapeString1 +'\nProblem Description and Definition - '+req.Problem_Description_and_Definition__c;
               // feedItemsList.add(post); 
        insert feedItemsList;
Insert failed. First exception on row 0; first error: INVALID_MARKUP, Error while parsing Rich Text Content: Unsupported HTML tag or attribute encountered.

Please help.
Hi All,

I have a problem with this Challenge : https://developer.salesforce.com/trailhead/microsoft_dotnet/apex_basics_dotnet/execution_context


public class AccountTriggerHandler {
    public static void CreateAccounts(List<Account> acclist){
        for(Account a:acclist){


trigger AccountTrigger on Account (before insert) 
    if (Trigger.isBefore && Trigger.isInsert) {

public class AccountTriggerTest {
    @isTest static void TestCreate200Records(){
        // Test Setup data
        // Create 200 new Accounts
        List<Account> accts = new List<Account>();
        for(Integer i=0; i < 200; i++) {
            Account acct = new Account(Name='Test Account ' + i, BillingState = 'CA');
            insert acct;
            for (Account a:accts){
                System.assertEquals('CA', a.ShippingState, 'ERROR');


Can you help me please??
This is the Challenge:

To pass this challenge, create an Apex class that inserts a new account named after an incoming parameter. If the account is successfully inserted, the method should return the account record. If a DML exception occurs, the method should return null.The Apex class must be called 'AccountHandler' and be in the public scope.
The Apex class must have a public static method called 'insertNewAccount'.
The 'insertNewAccount' method must accept an incoming string as a parameter, name the account after the parameter, insert it into the system and then return the account record.
The 'insertNewAccount' method must also accept an empty string, catch the failed DML and return null.

My Class:

public class AccountHandler {

    public static Account insertNewAccount (String accName, Account a) {
          a.name = accName;
         insert a;
        return a;
        catch(Exception e) {
            return null;

User-added image

Throwing this error, how many times i modified the class.
what is the correct class.?