Salesforce

Using the Replace Function in Forms

« Go Back
Information
Using the Replace Function in Forms
using-the-replace-function-in-forms
Article Details

Introduction

The replace function will allow a user to replace values in a text field with different values. For example, you could have a text field with the default value of "Hello World" and replace the "Hello" with "Hi" or any other value by inserting a second text field below, and use the replace function in the default value of the second text field.


Using replace option

Syntax - replace({text1},"Hello","Hi")  

note: some characters will need to be escaped using double back slash eg full stop, which is seen as a wildcard character - please see examples below

(See screenshot below)

replace function

 

replace function defaults

 

replace function edit

will generate the output as below

worked example

Examples

  • If you need to strip all single quotes/apostrophes from a string?
 replaceAll({token},'\'','')
  • For replacing specific characters you need to add to backslash's before the character.  For example to remove a full stop you would use;
 replaceAll({text1},'\\.','')
  • To replace characters in a phrase
 replace('Hello Holly','H','B')

will return 'Bello Holly'

 replaceAll('Hello Holly','H','B')

will return 'Bello Bolly'

  • Replace all commas in text with a new line
 replaceAll({text1},',','\n')
  • Strip text that is not a letter/number/space
 replaceAll({selectedStreet},'[^A-Za-z0-9\\s]+','')
 

Further useful reading:

 

top of page

 
     
    • when using the replace function in Forms if the string is over 18 characters then the result will be an empty string.
    • The workaround for this is to use replaceAll.

     

    Powered by