Activity Forums Salesforce® Discussions Admin needs to preserve carriage returns in transfer of text fields in Salesforce

  • Admin needs to preserve carriage returns in transfer of text fields in Salesforce

    Posted by Radhakrishna on August 10, 2017 at 5:55 am

    Hello developers,
    I am working on an apex script to do a one time transfer of data from one object to another. One of the fields that has to be transferred is a large text area field. It will be transferred to a Rich text area field. I can't figure out how to preserve the carriage returns. Below is the simple version of my script that I have been using to try different things out. I know not to to put dmil inside of loops....again this is just a quick to find how to transfer the string. Without really understanding these different escape methods...I tried all of them...escapeEMCAScript, unescapeECMAScript, escapeHTML3 etc. But none of them work. Everything results in the string saved to the field without any returns.

     

    for(Project__c mp : [select Id, Brief__c, Opportunity__r.Description from Project__c

    where Id = 'a10N0000001hF0WIAU'])

    {

    mp.Brief__c = mp.Opportunity__r.Description.escapeHtml4();

    update mp;

    }

    PRANAV replied 6 years, 2 months ago 2 Members · 1 Reply
  • 1 Reply
  • PRANAV

    Member
    February 13, 2018 at 12:12 pm

    Hi

    I haven't tested this, but I think it might work - replace all newlines with an HTML break:

    for(Project__c mp : [select Id, Brief__c, Opportunity__r.Description from Project__cwhere Id = 'a10N0000001hF0WIAU'])
    {
    mp.Brief__c = mp.Opportunity__r.Description.replaceAll( '\\n', '<br/>' );
    update mp;
    }

    Hope this helps you.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos