0

I have three different issues. To start with, we have a custom solution to generate contract/offer documents (PDF) through Visualforce. The terms and conditions are saved in a rich text field of custom object and its value is printed in Visualforce. The issues are the following:

  1. Copy paste rich text value from sandbox to production does not work properly. I believe this is an API Version issue cause i am copying from sandbox to production where versions are different. And copy-paste does not work properly. When i do this between sandboxes, value of rich text remains the same. I have opened a case to Salesforce support for confirmation.
  2. As a workaround, i tried to do use SUBSTITUTE function to replace the necessary values. One of the values i need to replace is the following:
<apex:outputText rendered="{!IF(clause.csclm__Sequence__c < 12, true, false)}" escape="false" value="{!SUBSTITUTE(SUBSTITUTE(clause.csclm__Final_Rich_Text__c, 'Arial', 'Arial Unicode MS'), 'style=&quot;&quot;' , 'style=&quot;margin-top: 0pt; margin-bottom: 0pt;&quot;')}"></apex:outputText>

but does not seem to work. Should i use differently the double quote symbol? Because this is why the replacement does not work

  1. As far as i have seen, i can do SUBSTITUTE up to 3 (three) levels. I cannot use (SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE)))). I can only use up to: SUBSTITUTE(SUBSTITUTE(SUBSTITUTE))). If i want to do multiple SUBSTITUTIONS, what is the recommended way to achieve it?

2 Answers 2

1

Copy paste rich text value from sandbox to production does not work properly. I believe this is an API Version issue cause i am copying from sandbox to production where versions are different. And copy-paste does not work properly. When i do this between sandboxes, value of rich text remains the same. I have opened a case to Salesforce support for confirmation.

Without seeing more information, we can't answer this part. It could be a copy-paste problem elsewhere, such as if you try to copy-paste to Microsoft Word or not, or between different browsers. In the general sense, it should work correctly, the environment shouldn't matter.


As a workaround, i tried to do use SUBSTITUTE function to replace the necessary values. One of the values i need to replace is the following:

Two things here.

First, the < operator already returns a Boolean value, so you don't need the IF statement:

rendered="{!clause.csclm__Sequence__c < 12}" 

Second, once you're inside an expression, you don't need to escape quotes, and in fact, you should not escape quotes; it'll break the HTML in fun and exciting ways. It'll highlight weird in your code editor, but it does compile and run.

value="{!
    SUBSTITUTE(
        SUBSTITUTE(
            clause.csclm__Final_Rich_Text__c, 
            'Arial', 
            'Arial Unicode MS'
        ), 
        'style=""', 
        'style="margin-top: 0pt; margin-bottom: 0pt;"'
    )
}"

Notice how we can also use line breaks to make our code read cleaner.


As far as i have seen, i can do SUBSTITUTE up to 3 (three) levels. I cannot use (SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE)))). I can only use up to: SUBSTITUTE(SUBSTITUTE(SUBSTITUTE))). If i want to do multiple SUBSTITUTIONS, what is the recommended way to achieve it?

I don't know if there's an actual limit, but it's surely more than 3. I can trivially prove this with:

    <apex:outputText 
        value="{!
SUBSTITUTE(
    SUBSTITUTE(
        SUBSTITUTE(
            SUBSTITUTE(
                "a b c d", 
                "a", 
                "Hello"
            ), 
            "b", 
            "Brave"
        ),
        "c",
        "New"
    ),
    "d",
    "World"
)
        }" />

Which outputs:

Hello Brave New World

Make sure you're providing three parameters to each copy of SUBSTITUTE, and make sure you're closing the parentheses and adding commas appropriately.


Whatever's going on, it sounds more like a difference in the Rich Text Editor that you're using than anything else. This might or might not be Salesforce-specific, we just don't know from the details provided here. That said, moving records between organizations might be easier with an actual ETL (Extract-Transform-Load) tool, such as the Data Loader. This avoids any ambiguity that may arise from copy-pasting, since it uses a standard API to load/save the data, or using a plain text field in a Visualforce page to copy-paste the raw HTML without interpretation.

4
  • Hello @sfdcfox and thanks a lot for the explanation. Really appreciate it. However, when i try to use: <apex:outputText rendered="{!clause.csclm__Sequence__c < 12}" escape="false" value="{!SUBSTITUTE(SUBSTITUTE(clause.csclm__Final_Rich_Text__c, 'Arial', 'Arial Unicode MS'), 'style=" "', 'style="margin-top: 0pt; margin-bottom: 0pt; "' ) }"></apex:outputText>, i get an error: The element type "apex:outputText" must be aterminated by the matching end-tag. I have this problem when using double quotes ("). any ideas why? Thanks Sep 26, 2022 at 5:41
  • @GiorgosGalaios I put your code in my org, I found out that Visualforce wants you to escape quotes in a specific manner (\"). Try this: value="{!SUBSTITUTE(SUBSTITUTE(clause.csclm__Final_Rich_Text__c,'Arial','Arial Unicode MS'), 'style=\"\"', 'style=\"margin-top: 0pt; margin-bottom: 0pt;\"')}".
    – sfdcfox
    Sep 26, 2022 at 10:49
  • Still i get the same error :( Sep 26, 2022 at 13:26
  • I put: value="{!SUBSTITUTE(SUBSTITUTE(clause.csclm__Final_Rich_Text__c,'Arial','Arial Unicode MS'), 'style=\"\"', 'style=\"margin-top: 0pt; margin-bottom: 0pt;\"')}" and get "The element type "apex:outputText" must be terminated by the matching end-tag "</apex:outputText>"." Does this work in your org? Sep 26, 2022 at 13:27
0

Finally, after Production was moved to winter'23 version, issue was resolved. My assumption regarding the API Version seems that was correct.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .